#include<iostream>
int main(){
using std::cout;
cout.setf(std::ios::left);
int w = cout.width();
cout << "default field width = " << w << "\n";
cout.width();
cout << "N" << ":";
cout.width();
cout << "N * N" << "\n";
for (long i = ; i <= ; i *= ){
cout.width();
cout << i << ':';
cout.width();
cout << i * i << "\n";
}
return ;
}
注意那行绿色的
是对全局有效,左对齐.
(右对齐是默认的)
不过还有一个
cout<<right<<setw()<<"";
cout<<left<<setw()<<"";
这个就可以实现左边右边
cout<<right<<setw()<<setfill('*')<<"";
cout<<left<<setw()<<"";
setfill慎用!
他也是对全局有效的!