Cpp-standard-library-cpp-bitset-to-ulong

提供:Dev Guides
移動先:案内検索

C ++ビットセットライブラリ-to_ulong()関数

宣言

以下は、std
bitsetヘッダーからのstd :: bitset :: to_ulong()関数の宣言です。

C 98

unsigned long to_ulong() const;

パラメーター

None

戻り値

ビットセットを符号なしの長い数値として返します。

例外

例外がスローされた場合、ビットセットの変更はありません。

次の例は、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