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/archive/2012/04/03/2431419.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    c++设置左对齐

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/45975

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 下午10:27
下一篇 2023年2月8日 下午10:27

相关推荐