C++ C++;setw移动整个生产线,而不仅仅是需要的部分

C++ C++;setw移动整个生产线,而不仅仅是需要的部分,c++,C++,我正在尝试使用setw清理程序的输出。我希望在“要订购的假脱机总数”和输出之间有空格 编辑这就是我要做的: 这就是我得到的 以下是我到目前为止的情况: 更新代码 /********************************************/ // Name: results / // Description: Print results / // Parameters: N/A

我正在尝试使用setw清理程序的输出。我希望在“要订购的假脱机总数”和输出之间有空格

编辑这就是我要做的:

这就是我得到的 以下是我到目前为止的情况: 更新代码

/********************************************/
// Name: results                             /
// Description: Print results                /
// Parameters: N/A                           /
// Reture Value: N/A                         /
/********************************************/
void results(int spoolnumber, int subtotalspool, float shippingcost, float totalcost)
{
  cout << left << setw (45) << "Total number of spools to be ordered is: " << right << spoolnumber << endl << endl;

  cout << left << setw (45) << "The subtotal for the spools is:" << right << "$" << subtotalspool << endl << endl;

  cout << "The shipping cost is: $" << shippingcost << endl << endl;

  cout << "The total cost is: $" << totalcost << endl << endl;

  return;
}
/********************************************/
//名称:结果/
//说明:打印结果/
//参数:不适用/
//回收值:不适用/
/********************************************/
无效结果(整数假脱机编号、整数小计假脱机、浮动发货成本、浮动总成本)
{
你也可以这样做

cout << left << setw (45) <<  "Total number of spools to be ordered is: " << spoolnumber << endl << endl;

cout这也不行,如果这有助于使我的问题更精确的话,我提供了一个简短的示例图像。编辑:没错,我需要使用left和not right这两个词,但现在零没有对齐。我甚至补充说,我想问题是你正在将setw应用于$符号。我不确定这是否是最好的方法但是您可以使用stringstream将$与spoolnumber合并。请参阅editRob的规则#8:当您指的是
“\n”
,请不要说
endl
。请参阅。+1根据反馈澄清问题@Steve Townsend:问题越好,答案越好。@Hasturkun:谢谢添加图像代码。忘了它。
stringstream ss;
ss << "$" << spoolnumber
cout << left << setw (45) <<  "Total number of spools to be ordered is: " << right << setw(5) << ss.str() << endl << endl;