转换为如果使用将生成包含的位顺序进行初始化bitset的整数bitset对象。
unsigned long to_ulong( ) const;
返回值
如果使用将生成一bitset的位在bitset的初始化的整数。
备注
将成员函数将返回具有1和0位数同一序列的整数与依次位于bitset包含的内容。
成员函数引发 overflow_error,如果在位有任何位对于不能表示为类型 unsigned long的值的一个位值*。*
示例
// bitset_to_ulong.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<5> b1 ( 7 );
cout << "The ordered set of bits in the bitset<5> b1( 7 )"
<< "\n that was generated by the number 7 is: ( "
<< b1 << " )" << endl;
unsigned long int i;
i = b1.to_ulong( );
cout << "The integer returned from the bitset b1,"
<< "\n by the member function to_long( ), that"
<< "\n generated the bits as a base two number is: "
<< i << "." << endl;
}
要求
标头: <bitset>
命名空间: std