【问题标题】:Aligning text to the right in the C++ console在 C++ 控制台中将文本右对齐
【发布时间】:2011-04-18 23:45:57
【问题描述】:

如何格式化我的控制台输出,使其与 C++ 中的右侧对齐?

【问题讨论】:

  • 在文本前面放置一堆空格,使其与 80 列控制台的右边缘对齐? :)

标签: c++ text-alignment


【解决方案1】:

使用操纵器标志std::right

Example

这行得通...

#include<iostream>
using std::cout;
using std::endl;


#include<iomanip>
using std::setw;

int main(){

 int x = 12345;

 cout << "Blah Blah Blah" << endl << setw(80) <<  x << endl;

 system("pause");

 return 0;
}

【讨论】:

  • @Ben Voigt,谢谢老兄,这就是两个解决方案选项之间存在 OR 的原因。评论前请阅读。
  • 啊,好的:“初始化时,标准流中的adjustfield标志设置为正确”
  • 示例链接不再起作用,在帖子中内嵌解决方案或更新链接。
猜你喜欢
  • 1970-01-01
  • 2014-10-26
  • 2020-03-24
  • 1970-01-01
  • 2012-05-05
  • 2021-04-23
  • 1970-01-01
  • 1970-01-01
  • 2019-04-20
相关资源
最近更新 更多