📄 formatdemo.cpp
字号:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// formatting using manipulators
int main()
{
const double CENTIPI = 100 * acos(-1); // arccos(-1) = PI
const int MAX = 10;
const int TAB = 15;
int k;
cout << "default setting " << CENTIPI << ", with setprecision(4), "
<< setprecision(4) << CENTIPI << endl;
cout << "\nfixed floating-point, precision varies, fixed/scientific\n" << endl;
for(k=0; k < MAX; k++)
{ cout << left << "pre. " << k << "\t" << setprecision(k) << setw(TAB)
<< fixed << CENTIPI << scientific << "\t" << CENTIPI << endl;
}
cout << endl << "width and justification vary, fixed, precision 2\n" << endl;
cout << setprecision(2) << fixed;
for(k=3; k < MAX+3; k++)
{ cout << "wid. " << k << "\t+" << left << setw(k) << CENTIPI << right
<< "+\t\t-" << setw(k) << CENTIPI << "-" << endl;
}
cout << endl << "repeated, fill char = @\n" << endl;
cout << setfill('@');
for(k=3; k < MAX+3; k++)
{ cout << "wid. " << k << "\t+" << left << setw(k) << CENTIPI << right
<< "+\t\t-" << setw(k) << CENTIPI << "-" << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -