5.cout控制格式

使用hex和oct以上述三种格式显示十进制值42。默认格式为十进制,在修改格式之前,原来的格式将一直有效

void hexoct2(void)
{
    int chest=42;
    int waist=42;
    int inseam=42;
 
    cout<<"monsieur cuts a striking figure!"<<endl;
    cout<<"chest="<<chest<<" (decimal for 42)"<<endl;
    cout<<hex;//manipulator for changing number base
    cout<<"waist="<<waist<<" (hexadecimal for 42)"<<endl;
    cout<<oct;//manipulator for changing number base
    cout<<"inseam="<<inseam<<" (octal for 42)"<<endl;
 
    cin.get();
}

猜你喜欢

转载自www.cnblogs.com/foremember/p/10472240.html