December 2018
Intermediate to advanced
702 pages
20h 9m
English
To manipulate an std::vector<bool>, use the same methods you would use for an std::vector<T>, as shown in the following examples:
std::vector<bool> bv; // []
bv.push_back(true); // [1] bv.push_back(true); // [1, 1] bv.push_back(false); // [1, 1, 0] bv.push_back(false); // [1, 1, 0, 0] bv.push_back(true); // [1, 1, 0, 0, 1]
bv[3] = true; // [1, 1, 0, 1, 1]
auto count_of_ones = std::count(bv.cbegin(), bv.cend(), true);
bv.erase(bv.begin() + 2); // [1, 1, 1, 1]
Read now
Unlock full access