切换值。bitset 的所有位或切换位中的指定位置。
bitset<N>& flip( );
bitset<N>& flip(
size_t _Pos
);
参数
- _Pos
值将切换位的位置。
返回值
成员函数调用修改的 bitset 的副本。
备注
第二个成员函数 out_of_range 引发异常,如果作为参数指定位置大于 bitset<"> 位范围切换 N 的 显著。
示例
// bitset_flip.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<5> b1 ( 6 );
cout << "The collection of bits in the original bitset is: ( "
<< b1 << " )" << endl;
bitset<5> fb1;
fb1 = b1.flip ( );
cout << "After flipping all the bits, the bitset becomes: ( "
<< fb1 << " )" << endl;
bitset<5> f3b1;
f3b1 = b1.flip ( 3 );
cout << "After flipping the fourth bit, the bitset becomes: ( "
<< f3b1 << " )" << endl << endl;
bitset<5> b2;
int i;
for ( i = 0 ; i <= 4 ; i++ )
{
b2.flip(i);
cout << b2 << " The bit flipped is in position "
<< i << ".\n";
}
}
要求
页眉: <bitset>
命名空间: std