Cpp-standard-library-cpp-bitset-count
提供:Dev Guides
C ++ビットセットライブラリ-count()関数
説明
- C ++関数* std
- bitset :: count()*は、ビットセットから設定ビットの数をカウントします。
宣言
- 以下は、std
- bitsetヘッダーからのstd :: bitset :: count()関数の宣言です。
C 98
size_t count() const;
C 11
size_t count() const noexcept;
パラメーター
None
戻り値
設定ビット数を返します。
例外
このメンバー関数は例外をスローしません。
例
- 次の例は、std
- bitset :: count()関数の使用法を示しています。
#include <iostream>
#include <bitset>
using namespace std;
int main(void) {
bitset<4> b("1110");
cout << "In bitset " << b << ", " << b.count() << " bits are set." << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
In bitset 1110, 3 bits are set.