码迷,mamicode.com
首页 > 其他好文 > 详细

cout 按进制数出

时间:2018-08-05 14:57:46      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:16进制   include   man   eof   bit   int   oct   color   class   

头文件:

  #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 }

 

cout 按进制数出

标签:16进制   include   man   eof   bit   int   oct   color   class   

原文地址:https://www.cnblogs.com/liubilan/p/9425436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!