Bitsets

来源:互联网 发布:地狱通信软件下载 编辑:程序博客网 时间:2024/06/11 20:08
#include <iostream>
#include <bitset>
using namespace std;
int main()
{
enum Color {red,yellow,green,blue,white,black,numColors};
bitset<numColors> usedColors;
usedColors.set(red);
usedColors.set(blue);
cout << "bitfield of used colors: " << usedColors << endl;
cout << "number of used colors: " << usedColors.count() << endl;
cout << "bitfield of unused colors: " << ~usedColors << endl;

cout << "any color: " << usedColors.any() << endl;

usedColors.reset(red);

if (usedColors.any()) {
for (int c = 0; c < numColors; ++c)
{
if (usedColors[(Color)c])
{
cout << "现在使用的颜色是:" << (Color)c << endl;
}
}
}
cin.get();
}
0 0
原创粉丝点击