Cpp-standard-library-cpp-bitset-test
提供:Dev Guides
C ++ビットセットライブラリ-test()関数
説明
- C ++関数* std
- bitset :: test()* N ^ th ^ビットが設定されているかどうかをテストします。
宣言
- 以下は、std
- bitsetヘッダーからのstd :: bitset :: test()関数の宣言です。
C 98
bool test (size_t pos) const;
パラメーター
None
戻り値
N ^ th ^ビットが設定されている場合はtrue、そうでない場合はfalseを返します。
例外
「+ pos 」がビットセットサイズ以上の場合、「 out_of_range +」例外をスローします。
例
- 次の例は、std
- bitset :: test()関数の使用法を示しています。
#include <iostream>
#include <bitset>
using namespace std;
int main(void) {
bitset<4> b(1010);
if (b.test(1))
cout << "1st bit is set." << endl;
if (!b.test(0))
cout << "0th bit is not set." << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
1st bit is set.
0th bit is not set.