hex,Hexadecimal .十六进制。
dec,Decimal ,十进制。
oct,Octal ,八进制。
bin,Binary,二进制。
直接在cout的后面加上转义字符。
cout<<转义字符<<数据<<endl;
#include <iostream>
using namespace std;
class number
{
protected:
int value;
public:
number(int i)
{
value=i;
}
virtual void show()=0;
};
class hextype:public number
{
public:
hextype(int x):number(x)
{
}
void show()
{
cout<<hex<<value<<endl;
}
};
class octtype:public number
{
public:
octtype(int x):number(x)
{
}
void show()
{
cout<<oct<<value<<endl;
}
};
class dectype:public number
{
public:
dectype(int x):number(x)
{
}
void show()
{
cout<<dec<<value<<endl;
}
};
int main ()
{
number *p;
hextype h(100);
octtype o(100);
dectype d(100);
p=&h;
p->show();
p=&o;
p->show();
p=&d;
p->show();
return 0;
}
更多推荐
进制转换hex,dec,oct,bin
发布评论