返回序列中位设置的位的数目。
size_t count( ) const;
返回值
在序列位设置的位的数目。
示例
在编译此示例与 /Wp64 标志或在 64 位平台时,编译器将生成警告 C4267。 有关该警告的更多信息,请参见 编译器警告(等级 3)C4267。
// bitset_count.cpp
// compile with: /EHsc
#include <bitset>
#include <iostream>
int main( )
{
using namespace std;
bitset<5> b1(4);
cout << "The collection of bits in the original bitset is: ( "
<< b1 << " )" << endl;
size_t i;
i = b1.count();
cout << "The number of bits in the bitset set to 1 is: "
<< i << "." << endl;
bitset<5> fb1;
fb1 = b1.flip();
cout << "The collection of flipped bits in the modified bitset "
<< "is: ( " << b1 << " )" << endl;
size_t ii;
ii = fb1.count();
cout << "The number of bits in the bitset set to 1 is: "
<< ii << "." << endl;
}
要求
页眉: <bitset>
命名空间: std