bitset::set

bitset のすべてのビットを 1 に設定するか、指定位置に 1. にビットがセットされます。

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

パラメーター

  • _Pos
    設定する必要 bitset ビットの位置に値を代入します。

  • _Val
    指定した位置のビットに割り当てる値。

戻り値

メンバー関数が呼び出された bitset のコピー。

解説

2 番目のメンバー関数は、で指定された位置が 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 Class