名稱空間
變體
操作

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

來自 cppreference.com
< cpp‎ | 容器‎ | vector bool
 
 
 
 
在標頭檔案 <vector> 中定義
void flip();
(C++20 起為 constexpr)

vector 中切換每個 bool(替換為它的相反值)。

[編輯] 示例

#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

[編輯] 參閱

訪問指定的元素
(std::vector<T,Allocator> 的公開成員函式) [編輯]
切換位的值
(std::bitset<N> 的公開成員函式) [編輯]