共用方式為


vector<bool>::flip

Reverses all bits in a vector<bool>.

void flip();

Example

// vector_bool_flip.cpp
// compile with: /EHsc /W4
#include <vector>
#include <iostream>

int main()
{
    using namespace std;
    cout << boolalpha; // format output for subsequent code

    vector<bool> vb = { true, false, false, true, true };
    cout << "The vector is:" << endl << "    ";
    for (const auto& b : vb) {
        cout << b << " ";
    }
    cout << endl;

    vb.flip();

    cout << "The flipped vector is:" << endl << "    ";
    for (const auto& b : vb) {
        cout << b << " ";
    }
    cout << endl;
}

Output

The vector is:
    true false false true true
The flipped vector is:
    false true true false false

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector Class

Standard Template Library