您的位置:首页 > 其它

第十四周程序阅读例二

2015-06-10 08:34 232 查看
#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;
}

运行结果:



学习心得:

运用到了,设置输出格式状态setf()和中指已设置的输出格式状态unsetf()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: