次の方法で共有


bitset::operator[]

ビットセットが変更可能な場合ビットセット内の指定した位置のビットへの参照を返します。; それ以外の場合は、その位置のビットの値を返します。

bool operator[](
   size_t _Pos
) const;
reference operator[](
   size_t _Pos
);

パラメーター

  • _Pos
    ビットセット内のビット位置を検索します。

解説

_SECURE_SCL 1 でコンパイルすると、ランタイム エラーがビットセットの境界の外に要素にアクセスしようとすると発生します。詳細については、「チェックを行う反復子」を参照してください。

使用例

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

int main( )
{
   using namespace std;
   bool b;
   bitset<5> b1 ( 6 );
   cout << "The initialized bitset<5> b1( 2 ) is: ( "<< b1 << " )."
        << endl;

   int i;
   for ( i = 0 ; i <= 4 ; i++ )
   {
      b = b1[ i ];
      cout << "  The bit in position "
           << i << " is " << b << ".\n";
   }
}

出力

The initialized bitset<5> b1( 2 ) is: ( 00110 ).
  The bit in position 0 is 0.
  The bit in position 1 is 1.
  The bit in position 2 is 1.
  The bit in position 3 is 0.
  The bit in position 4 is 0.

必要条件

ヘッダー: の <ビットセット>

名前空間: std

参照

関連項目

bitset クラス