std::
bitset::to_ullong
公众成员函数 <bitset>
unsigned long long to_ullong() const;
|
转换为无符号long long整数
返回一个unsigned long long对象,其整型值与bitset对象的位值相同。
如果bitset size太大,无法用unsigned long long类型的值表示,则该函数会抛出overflow_error类型的异常。
☲ 参数
-
none
☉ 返回值
与bitset对象表示的相同整数值。
☣ 示例
// bitset::to_ullong
#include <iostream> // std::cout
#include <bitset> // std::bitset
int main ()
{
std::bitset<4> foo; // foo: 0000
foo.set(); // foo: 1111
std::cout << foo << " as an integer is: " << foo.to_ullong() << '\n';
return 0;
}
|
输出:
1111 as an integer is: 15
⇄ 数据竞争
访问bitset对象。
☂ 异常安全性
强保证:如果抛出异常,bitset对象不会发生任何变化。
如果bitset大小太大而无法用返回类型表示,则会抛出overflow_error。
🍄 另请参阅