c++设置左对齐
2012-04-03 22:32 youxin 阅读(4345) 评论(0) 编辑 收藏 举报方法一:
cout.flags (ios::left);//设置对齐的标志位为左
2. cout<<left
对齐选项:(left, right or internal).
manip setw ( int n );默认右对齐
setw(n) 设置固定宽度
Set field width
Sets the number of characters to be used as the field width for the next insertion operation.
smanip setfill ( char c );
// setfill example
#include <iostream>
#include <iomanip>
using namespace std;
int main () {
cout << setfill ('x') << setw (10);
cout << 77 << endl;
return 0;
}
This code uses setfill to set the fill character to 'x'. The output of this example is something similar to:
xxxxxxxx77想要输出77********
cout<<left<<setw(10)<<setfill('x') 左对齐