输放输出格式控制

情到浓时终转凉″ 提交于 2019-11-27 00:12:11

#include <iostream>
using namespace std;
int main()
{int a=21;
 cout.setf(ios::showbase);
 cout<<"dec:"<<a<<endl;
 cout.unsetf(ios::dec);
 cout.setf(ios::hex);
 cout<<"hex:"<<a<<endl;
 cout.unsetf(ios::hex);
 cout.setf(ios::oct);
 cout<<"oct:"<<a<<endl;
 char *pt="China";
 cout.width(10);
 cout<<pt<<endl;
 cout.width(10);
 cout.fill('*');
 cout<<pt<<endl;
 double pi=22.0/7.0;
 cout.setf(ios::scientific);
 cout<<"pi=";
 cout.width(14);
 cout<<pi<<endl;
 cout.unsetf(ios::scientific);
 cout.setf(ios::fixed);
 cout.width(12);
 cout.setf(ios::showpos);
 cout.setf(ios::internal);
 cout.precision(6);
 cout<<pi<<endl;
 return 0;
}

转载于:https://www.cnblogs.com/GavinDai/archive/2011/11/15/2250045.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!