bitset::element_type
為資料型別的 bool 一個同義資料表,並且可以用來參考項目 (在 bitset 的型別。
typedef bool element_type;
範例
// bitset_elem_type.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<3> b1 ( 2 );
cout << "Original bitset b1(6) is: ( "<< b1 << " )"
<< endl;
//Compare two ways to reference bits in a bitset
bool b;
bitset<5>::element_type e;
b = b1.test ( 2 );
if ( b )
cout << "The bit at position 2 of bitset b1"
<< "has a value of 1." << endl;
else
cout << "The bit at position 2 of bitset b1"
<< "has a value of 0." << endl;
b1[2] = 1;
cout << "Bitset b1 modified by b1[2] = 1 is: ( "<< b1 << " )"
<< endl;
e = b1.test ( 2 );
if ( e )
cout << "The bit at position 2 of bitset b1"
<< "has a value of 1." << endl;
else
cout << "The bit at position 2 of bitset b1"
<< "has a value of 0." << endl;
}
需求
標題: <bitset>
命名空間: std