C++ Bitset 库 - to_ulong() 函数
声明
以下是 std::bitset::to_ulong() 函数形式 std::bitset 头的声明。
C++98
unsigned long to_ulong() const;
参数
None
返回值
将位集返回为无符号长整数。
异常
如果抛出异常,bitset 不会发生变化。
示例
以下示例显示了 std::bitset::to_ulong() 函数的用法。
#include <iostream>
#include <bitset>
#include <typeinfo>
using namespace std;
int main(void) {
bitset<4> b("1010");;
auto result = b.to_ulong();
cout << "Decimal representation of " << b << " = " << result << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Decimal representation of 1010 = 10

