我很确定这是一个关于格式化的简单问题,但这就是我想要完成的事情:
我想用cout将数据输出到屏幕上.我想以表格格式输出.我的意思是列和行应该正确对齐.例:
Test 1
Test2 2
Iamlongverylongblah 2
Etc 1
Run Code Online (Sandbox Code Playgroud)
我只关心单独的行,所以我现在输出的行(不工作)是
cout << var1 <<"\ t\t"<< var2 << endl;
这给了我类似的东西:
Test 1
Test2 2
Iamlongverylongblah 2
Etc 1
Run Code Online (Sandbox Code Playgroud) 我已经研究了几种解决方案来解决我的问题,但似乎没有什么对我有用。我希望我的输出能够对齐此代码上的所有姓名、所选号码和中奖金额。目前它输出:
3454 Atkins, Joe 7 6 5 4 3 2 1 7 $20.00
4321 Barber, John 11 22 7 8 45 12 10 1 $0.00
8976 Dollar, Kim 44 33 22 11 10 9 4 1 $0.00
Run Code Online (Sandbox Code Playgroud)
我相信我需要将名称右对齐才能解决此问题,但我尝试过的任何方法都不起作用。这是我的代码:
cout << student_info[i].id_num;
cout << setw(10) << student_info[i].student_name << setw(10);
for(int j = 0; j < LOTTERYNUMBERS; j++)
cout << student_info[i].lotteryNumbers[j] << " ";
cout << setw(10) << student_info[i].lotteryMatches << setw(10) << setprecision(2)
<< fixed << showpoint << "$" << student_info[i].prizeMoney << …Run Code Online (Sandbox Code Playgroud)