十五周实验报告(三)
来源:互联网 发布:安卓软件接口 编辑:程序博客网 时间:2024/05/29 14:35
#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"; cout<<setw(10)<<pt<<endl; //输出的字符占十个字符的长度,默认靠左 cout<<setfill('*')<<setw(10)<<pt<<endl; //输出的字符占十个字符的长度默认靠左不够的用*号补double pi=22.0/7.0; cout<<setiosflags(ios::scientific)<<setprecision(8);//浮点数以科学计数法输出,精确位数为八位cout<<"pi="<<pi<<endl; //输出字符串及pi的值 cout<<"pi="<<setprecision(4)<<pi<<endl; //输出精确位数为四位pi的值 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; // 默认输出a的值是以十进制cout.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"; cout.width(10); //指定宽度为十cout<<pt<<endl; //输出ptcout.width(10); //指定宽度为十cout.fill('*'); //指定空白用 '*'填充cout<<pt<<endl; //输出ptdouble pi=22.0/7.0; cout.setf(ios::scientific); // 设置输出格式为科学计数法cout<<"pi="; //输出字符串"pi="cout.width(14); //指定宽度为十四cout<<pi<<endl; //输出picout.unsetf(ios::scientific); //终止科学计数法cout.setf(ios::fixed); //指定用定点形式输出cout.width(12); //指定宽度为十二cout.setf(ios::showpos); //输出时显示“+”号cout.setf(ios::internal); //符号在左侧cout.precision(6); //保留六位小数cout<<pi<<endl; //输出pisystem("pause");return 0;}