共用方式為


bitset::operator[]

如果 bitset 是可修改的,則會傳回對位元組的參考在 bitset 中指定位置的;否則,會傳回位元組的值在該位置。

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

參數

  • _Pos
    在 bitset 內的位元位置。

備註

在以 _SECURE_SCL 1 時,執行時會發生錯誤,如果您嘗試存取正在 bitset 範圍以外的項目。如需詳細資訊,請參閱已檢查的迭代器

範例

// 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";
   }
}

Output

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.

需求

標題: <bitset>

命名空間: std

請參閱

參考

bitset 類別