c++中,怎么用cout输出八进制的数值??

怎么才能使得前边有个0
比如:cout<<oct<<146<<endl;
输出的是222. 怎么修改才能使其输出为: 0222

  //  ä½¿ç”¨cout/pintf输出16进制,8进制,2进制数据

  #include <iostream>

  #include <bitset>

  #include <stdlib.h>

  using namespace std;

  int main()

  {

  printf("  ä½¿ç”¨cout/pintf输出16进制,8进制,2进制数据\n");

  printf(" - http://blog.csdn.net/morewindows/article/details/16358511 -\n");

  printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");

  

  int a = 100;

  cout<<"十进制    "<<a<<endl;

  cout<<"十六进制  "<<hex<<a<<endl;

  cout<<"八进制    "<<oct<<a<<endl;

  cout<<"二进制    "<<bitset<8>(a)<<"   "<<bitset<32>(a)<<endl;  // 这里使用了bitset类来输出2进制数据

  

  cout<<"--------------------------------"<<endl;

  

  printf("十进制    %d\n", a);

  printf("十六进制  %x\n", a);

  printf("八进制    %o\n", a);

  char binary_text[100];

  itoa(a, binary_text, 2);

  printf("二进制    %s\n", binary_text);

  return 0;

  }


温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-09-16
cout << showbase << oct << 146 << endl;本回答被提问者采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网