C++ 位集庫 - to_ulong() 函式



宣告

以下是來自 std::bitset 標頭檔案的 std::bitset::to_ulong() 函式宣告。

C++98

unsigned long to_ulong() const;

引數

返回值

將bitset作為無符號長整型數字返回。

異常

如果丟擲異常,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
bitset.htm
廣告
© . All rights reserved.