标签:set div field default 左右 col stream cout ios
#include<iostream> int main(){ using std::cout; cout.setf(std::ios::left); int w = cout.width(); cout << "default field width = " << w << "\n"; cout.width(5); cout << "N" << ":"; cout.width(8); cout << "N * N" << "\n"; for (long i = 1; i <= 100; i *= 10){ cout.width(5); cout << i << ‘:‘; cout.width(8); cout << i * i << "\n"; } return 0; }
注意那行绿色的
是对全局有效,左对齐.
(右对齐是默认的)
不过还有一个
1 cout<<right<<setw(4)<<"111"; 2 cout<<left<<setw(5)<<"222";
这个就可以实现左边右边
1 cout<<right<<setw(4)<<setfill(‘*‘)<<"111"; 2 cout<<left<<setw(5)<<"222";
setfill慎用!
他也是对全局有效的!
标签:set div field default 左右 col stream cout ios
原文地址:https://www.cnblogs.com/zhmlzhml/p/12457717.html