您的位置:首页 > 编程语言 > C语言/C++

算法之旅,直奔<bitset>之五 count

2013-12-24 16:00 405 查看

count(vs2010)


引言
这是我学习总结<bitset>的第五篇。有时候我们需要计算位集合中1或0的个数,count来帮助你。
作用
count的作用计算位集合中1或0的个数。
实验
             


代码
test.cpp
#include <iostream>       // std::cout
#include <string>         // std::string
#include <bitset>         // std::bitset

int main ()
{
std::bitset<8> foo (std::string("10110011"));

std::cout << foo << " has ";
std::cout << foo.count() << " ones and ";
std::cout << (foo.size()-foo.count()) << " zeros.\n";
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c++ vs2010 bitset