cout 按进制数出

头文件:

  #include<iostream>
  #include<iomanip>  //setbase()
  #include<bitset>  //bitset<>

 

setbase只能用于设置8,10,16进制输出

 

 1 #include<iostream>
 2 #include<iomanip>
 3 #include<bitset>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int x = 18;
 9     cout<<hex<<x<<endl;
10     cout<<oct<<x<<endl;
11     cout<<dec<<x<<endl;
12     cout<<bitset<sizeof(int)*4>(x)<<endl;
13     cout<<setbase(16)<<x<<endl;
14     
15     return 0;
16 }

 

posted @ 2018-08-05 14:26  liubilan  阅读(228)  评论(0编辑  收藏  举报