public member function
<bitset>

std::bitset::to_ullong

unsigned long long to_ullong() const;
轉換為無符號長長整型
返回一個unsigned long long,其整數值與bitset具有相同的位設定。

如果bitset大小過大,無法用unsigned long long型別的值表示,則該函式會丟擲型別為overflow_error的異常。

引數



返回值

bitset物件具有相同位表示的整數值。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
// 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

另見