count(vs2010)
- 引言
这是我学习总结<bitset>的第五篇。有时候我们需要计算位集合中1或0的个数,count来帮助你。
- 作用
count的作用计算位集合中1或0的个数。
- 实验
![](https://img-blog.csdn.net/20131224155955078?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3FzX2V4cGVyaW1lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
- 代码
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;
}
#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;
}