命名空间
变体
操作

std::vector<bool,Allocator>::flip

来自 cppreference.cn
 
 
 
 
定义于头文件 <vector>
void flip();
(constexpr since C++20)

切换 vector 中每个 bool 值(替换为其相反值)。

[edit] 示例

#include <iostream>
#include <vector>
 
void print(const std::vector<bool>& vb)
{
    for (const bool b : vb)
        std::cout << b;
    std::cout << '\n';
}
 
int main()
{
    std::vector<bool> v{0, 1, 0, 1};
    print(v);
    v.flip();
    print(v);
}

输出

0101
1010

[edit] 参见

访问指定元素
(std::vector<T,Allocator> 的公共成员函数) [edit]
切换位的值
(std::bitset<N> 的公共成员函数) [edit]