如果 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