小结
BitSet即位图,是一个很长的“0/1”序列,他的功能就是存储0或者1。
bitset 转换成string,然后find出1的个数
using namespace std;
int main()
{
int in_n;
while(cin >> in_n)
{
bitset<32> b0(in_n);
string s = b0.to_string();
// 输出二进制
int count = 0;
size_t pos = s.find("1");
while(pos!=s.npos)
{
count++;
s =s.substr(1+pos,s.size());
pos = s.find("1");
}
cout << count << endl;
}
return 0;
}