#include "stdafx.h"
#include "iostream.h"
//using namespace std;
int main(int argc, char* argv[])
{
cout.width(20);
cout.fill('*');
cout<<endl<<" "<<endl;
cout.precision(4);
cout<<2007.3543<<endl;
printf("Hello World!\n");
return 0;
}
#include "stdafx.h"
#include "iostream.h"
//using namespace std;
#include "iomanip.h"
int main(int argc, char* argv[])
{
cout.width(20);
cout.fill('*');
cout<<endl<<" "<<endl;
cout.precision(4);
cout<<2007.3543<<endl;
printf("Hello World!\n");
cout<<setw(20)<<"hello !"<<endl;
cout<<setprecision(4)<<2004.345<<endl;
cout<<setw(20)<<setfill('*')<<""<<endl;
//cout<<scientific<<300.89<<endl;
cout<<oct<<9<<endl;//八进制转换
return 0;
}
本文介绍了使用C++进行控制台输出时的各种格式化技巧,包括如何设置输出宽度、填充字符、精度等,并展示了如何利用iomanip库来增强输出效果,例如八进制转换。
468

被折叠的 条评论
为什么被折叠?



