小编Jac*_*ell的帖子

格式化 C++ 输出中的空格

我已经研究了几种解决方案来解决我的问题,但似乎没有什么对我有用。我希望我的输出能够对齐此代码上的所有姓名、所选号码和中奖金额。目前它输出:

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)

c++

1
推荐指数
1
解决办法
4376
查看次数

标签 统计

c++ ×1