#include <iostream>#include <iomanip>using namespace std;int main(){int a;cout<<"input a:";cin>>a;cout<<"dec:"<<dec<<a<<endl;//以十进制形式输出整数cout<<"hex:"<<hex<<a<<endl;//以十六进制形式输出整数cout<<"oct:"<<setbase(8)<<a<<endl;//以八进制形式输出整数char *pt="Jerryson";//pt指向字符串"Jerryson"cout<<setw(10)<<pt<<endl;//指定域宽为10,输出字符串cout<<setfill('*')<<setw(10)<<pt<<endl;//指定域宽为10,输出字符串,空白处以'*'填充double pi=22.0/7.0;//计算pi的值cout<<setiosflags(ios::scientific)<<setprecision(8);//按指数形式输出,8位小数cout<<"pi="<<pi<<endl;//输出pi的值cout<<"pi="<<setprecision(4)<<pi<<endl;//改为4位小数cout<<"pi="<<setiosflags(ios::fixed)<<pi<<endl;//改为小数形式输出system("pause");return 0;}#include <iostream>using namespace std;int main( ){int a=54;cout.setf(ios::showbase);//设置输出时的基数符号cout<<"dec:"<<a<<endl;//默认以十进制形式输出acout.unsetf(ios::dec);//终止十进制的格式设置cout.setf(ios::hex);//设置以十六进制输出的状态cout<<"hex:"<<a<<endl;//以十六进制形式输出acout.unsetf(ios::hex);//终止十六进制的格式设置cout.setf(ios::oct);//设置以八进制输出的状态cout<<"oct:"<<a<<endl;//以八进制形式输出acout.unsetf(ios::oct);//终止以八进制输出的格式设置char *pt="Jerryson";//pt指向字符串"Jerryson"cout.width(10);//指定域宽为10cout<<pt<<endl;//输出字符串cout.width(10);//指定域宽为10cout.fill('*');//指定空白处以'*'填充cout<<pt<<endl;//输出字符串double pi=22.0/7.0;//计算pi的值cout.setf(ios::scientific);//指定用科学计数法输出cout<<"pi=";//输出"pi="cout.width(14);//指定域宽为14cout<<pi<<endl;//输出pi的值cout.unsetf(ios::scientific);//终止科学计数法状态cout.setf(ios::fixed);//指定用定点形式输出cout.width(12);//指定域宽为12cout.setf(ios::showpos);//在输出正数时显示输出"+"cout.setf(ios::internal);//数符出现在左侧cout.precision(6);//保留六位小数cout<<pi<<endl;//输出pi,注意数符"+"的位置system("pause");return 0;