📄 streamflags.cpp
字号:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
const double PI = acos(-1); // arccos(-1) = PI radians
const int MAX = 10; // max precision used in demo
int k;
// set right justified, fixed floating format
cout.setf(ios_base::right, ios_base::adjustfield);
cout.setf(ios_base::fixed, ios_base::floatfield);
cout << "fixed, right justified, width 10, precision varies\n" << endl;
for(k=0; k < MAX; k++)
{ cout.precision(k);
cout << k << "\t+";
cout.width(MAX);
cout << PI << "+" << endl;
}
// use different fill characters
int fillc = cout.fill();
cout.precision(2);
cout << "\nshow fill char, precision is 2\n" << endl;
for(k='a'; k <= 'd'; k++)
{ cout << "old fill = '" << char(fillc) << "' +";
cout.width(MAX);
cout.fill(k);
cout << PI << "+" << endl;
fillc = cout.fill();
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -