bitset::test
測試位元在 bitset 中指定的位置是否已設定為 1。
bool test(
size_t _Pos,
) const;
參數
- _Pos
位元的位置為其值將測試的 bitset。
傳回值
true ,如果引數位置的位元設定為 1;否則, false。
備註
成員函式擲回是 bitset 的大小小於或等於在引數中指定的位置上 out_of_range 例外狀況。
範例
// bitset_test.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<5> b1 ( 6 );
bool b;
bitset<5>::element_type e;
cout << "Original bitset b1(6) is: ( "<< b1 << " )"
<< endl;
cout << "Note: positions in a bitset are numbered\n"
<< " from the right starting with 0.\n" << endl;
b = b1.test ( 3 );
if ( b )
cout << "The bit at position 3 of bitset b1 "
<< "has a value of 1." << endl;
else
cout << "The bit at position 3 of bitset b1 "
<< "has a value of 0." << endl;
b1[3] = 1;
cout << "Bitset b1 modified by b1[3] = 1 is: ( "<< b1 << " )"
<< endl;
e = b1.test ( 3 );
if ( e )
cout << "The bit at position 3 of bitset b1 "
<< "has a value of 1." << endl;
else
cout << "The bit at position 3 of bitset b1 "
<< "has a value of 0." << endl;
}
需求
標題: <bitset>
命名空間: std