c++设置左对齐

方法一:

cout.flags (ios::left);//设置对齐的标志位为左
 
2. cout<<left 
对齐选项:(leftright 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') 左对齐
 
原文地址:https://www.cnblogs.com/youxin/p/2431419.html