Home C&C++函数库 c++ 语法 程序源码 Linux C库

std::

bitset::to_ulong

公众成员函数  <bitset>

unsigned long to_ulong() const;

转换为无符号长整数
返回一个unsigned long对象,其整型值与bitset对象的位值相同。

如果bitset size太大,无法用unsigned long类型的值表示,则该函数会抛出overflow_error类型的异常。

☲  参数


none

☉  返回值



与bitset对象表示的相同整数值。

☣  示例



// bitset::to_ulong
#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_ulong() << '\n';

  return 0;
}

输出:
1111 as an integer is: 15

⇄ 数据竞争


访问bitset对象。

☂ 异常安全性



强保证:如果抛出异常,bitset对象不会发生任何变化。
如果bitset大小太大而无法用返回类型表示,则会抛出overflow_error。

🍄  另请参阅



bitset::to_string 转换为字符串(公共成员函数)
bitset::bitset 构造函数(公共成员函数)

联系我们 免责声明 关于CandCplus 网站地图