多列中的C++对齐方式
C++ justification in multiple columns
我正试图编写一个程序来显示每个月的帐户余额,但在获得3列以正确证明时遇到了问题。预期的输出应该看起来像:
Total
Month Accumulated
------ -----------
2015 March 500.00
2015 April 1001.13
2015 May 1503.38
2015 June 2006.76
2015 July 2511.28
但我的输出是这样的:
Total
Month Accumulated
------ -----------
2015 March 500.00
2015 April 1001.13
2015 May 1503.38
2015 June 2006.76
2015 July 2511.28
我需要让数字在右边均匀排列。我似乎无法用正确的理由让它看起来更接近我需要的东西。我希望这里有人可能有一个我不知怎么忽略的简单解决方案。目前,这行是这样写的:
cout << setw(5) << left << currentYear << setw(18) << currentMonthName << totalAccum << endl;
如有任何建议,我们将不胜感激。谢谢
我想好了-需要添加一个"作为占位符,然后进行正确的对齐:cout << setw(5) << left << currentYear << setw(10) << currentMonthName << " " << right << setw(13) << totalAccum << endl;
相关文章:
- 为什么我可以将变量存储在不是其最小对齐方式的倍数的地址?
- 具有调整对齐方式的类型定义
- size_t的大小和对齐方式是否与ptrdiff_t相同?
- 逗号运算符在对齐方式中
- vcpkg:指定结构成员对齐方式
- 使用字节数组具有单字节对齐方式的结构是否安全
- C++对齐方式(何时使用对齐方式)
- 编译器会秘密增加结构的对齐方式吗?
- C++17 中函数参数的指针对齐方式
- 未在此范围内声明的对齐方式?
- 如何控制 clang 格式新行中 lessless 的对齐方式
- C++ 编译器正在更改我的结构的对齐方式.我怎样才能防止这种情况
- 是否有符合标准的方法来确定非静态杆件的对齐方式?
- 重载运算符是具有较小默认对齐方式的新增运算符
- 结构和对齐方式的大小
- Sizeof 舍入到对齐方式,但编译器仍将对象放在剩余的字节中
- 是否可以让 std::vector<char> 使用选定的内存对齐方式分配内存
- 对齐方式与指针中尾随零的数量有何关系
- 对齐方式究竟如何影响内存布局和新放置的巴哈维?
- 幻影类型是否与原始类型具有相同的对齐方式