2012年6月1日星期五

从c++开始5


hex(hexadecimal); oct(octal); 这两个标识符在命名空间std中,也是由iostream类文件提供的。他两个的作用是以不同的整形integer面貌来显示数据。


#include "stdafx.h"
#include <iostream>


int main()
{
using namespace std;
int chest = 42;//十进制
int waist = 42;//十进制
int inseam = 42;//十进制


cout<<"Monsieur cuts a striking figure!"<<endl;


cout<<"chest = "<<chest <<" (Decimal)" <<endl;//十进制

cout<<hex <<"waist = "<<waist <<" (Hexadecimal)" <<endl;//hex的出现告诉后面的cout 要用十六进制的方式输出显示插入的数据


cout<<cout <<"inseam = "<<inseam <<" (Octal)" <<endl;//oct也一样,告知后面用八进制显示插入数据


int m;
cin>>m;


return 0;
}

如下显示:

Monsieur cuts a striking figure!
chest = 42 (Decimal)
waist = 2a (Hexadecimal)
inseam = 2a (Octal)


没有评论:

发表评论