bitset::flip

切换所有位的值。bitset的或切换一个在指定的位置。

bitset<N>& flip( ); 
bitset<N>& flip(
   size_t _Pos
);

参数

  • _Pos
    值将切换位的位置。

返回值

成员函数调用已修改的bitset的副本。

备注

第二个成员函数引发异常 out_of_range,如果作为参数指定的该位置高于 bitset<N> 的大小位切换 的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

请参见

参考

bitset Class