我的程序中有一个小对齐问题。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setw(5) << "Sl. No:" << setw(15) << "Month" << setw(15) << "Name" << endl << endl;
cout << setw(5) << 1 << setw(15) << "January" << setw(15) << "Abhilash" << endl;
cout << setw(5) << 2 << setw(15) << "Februaury" << setw(15) << "Anandan" << endl;
cout << setw(5) << 3 << setw(15) << "March" << setw(15) << "Abhilash" << endl;
cout << setw(5) << 4 << setw(15) << "April" << setw(15) << "Anandan" << endl;
return 0;
}
在我得到的输出中,月份的名称不正确。
Sl. No: Month Name
1 January Abhilash
2 Februaury Anandan
3 March Abhilash
4 April Anandan
似乎是什么问题?
原文由 Babbzzz 发布,翻译遵循 CC BY-SA 4.0 许可协议
您也可以在
setw()
之前使用“\t”,以确保您不会进入空间。