C++ C++;多列对齐
我正试图写一个程序来显示每个月的帐户余额,但在获得正确的3列时遇到了一个问题。预期的输出应如下所示:C++ C++;多列对齐,c++,format,setw,C++,Format,Setw,我正试图写一个程序来显示每个月的帐户余额,但在获得正确的3列时遇到了一个问题。预期的输出应如下所示: Total Month Accumulated ------ ----------- 2015 March 500.00 2015 April 1001.13 2015 May 1503.38 2015 June
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我想出来了-需要添加一个“”作为占位符,然后进行正确的对齐:
std::setw()
和