以二进制位表示信息

以无符号数的与或来存储信息,类似于Windows窗口信息的设置



#include <bitset>

#include <string>
#include <iostream>
using namespace std;
//以二进制方式表示信息,每一个位或为0或为1表示信息真假
const int featureCount =8;
const unsigned Framed=1;
const unsigned Bordered=2;
const unsigned StdMenu=4;
const unsigned ToolBar=8;
const unsigned StatusBar=16;


class Window{
public:
Window(const string & n, unsigned f){
name=n;
features=bitset<featureCount>(f);
createWindow();
}
    Window(const char* n, unsigned f){
name=n;
features=bitset<featureCount>(f);
createWindow();
}
private:


void createWindow()
{
cout << endl << "Window feature for "
<< name<< "given bit mask " << features << ":" <<endl;


if(features[0])
cout<<"\t"<<"framed"<<endl;
        if(features[1])
cout<<"\t"<<"bordered"<<endl;
if(features[2])
cout<<"\t"<<"with standard menu"<<endl;
if(features[3])
cout<<"\t"<<"with tool bar"<<endl;
if(features[4])
cout<<"\t"<<"with status bar"<<endl;


}
    
string name;
bitset<featureCount> features;
};


int main()
{


Window w1("w1",Framed|ToolBar|StatusBar);
    Window w2("w2",ToolBar|Framed|StatusBar);
    Window w3("w3",Framed|StdMenu|ToolBar|StatusBar|Bordered);
return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值