共用方式為


bitset::set

設定 bitset 的所有位元設定為 1 或設定位元在指定的位置為 1。

bitset<N>& set( ); 
bitset<N>& set( 
   size_t _Pos,  
   bool _Val = true 
);

參數

  • _Pos
    位元組的位置。bitset 設定指派值。

  • _Val
    要指派的值為位元組在指定的位置。

傳回值

成員函式叫用 bitset 的複本。

備註

如果指定的位置大於 bitset,大小第二 + 成成員函式會擲回 out_of_range 例外狀況。

範例

// bitset_set.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>

int main( )
{
   using namespace std;

   bitset<5> b1 ( 6 );
   cout << "The set of bits in bitset<5> b1(6) is: ( "<< b1 << " )"
        << endl;

   bitset<5> b1s0;
   b1s0 = b1.set( 0 );
   cout << "The collecion of bits obtained from setting the\n"
        << " zeroth bit of bitset b1 is: ( "<< b1s0 << " )" 
        << endl;

   bitset<5> bs1;
   bs1 = b1.set( );
   cout << "The collecion of bits obtained from setting all the\n"
        << " elements of the bitset b1 is: ( "<< bs1 << " )"
        << endl;
}
  

需求

標題: <bitset>

命名空間: std

請參閱

參考

bitset 類別