Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何使用setw或tab在列中正确输出?_C++ - Fatal编程技术网

C++ 如何使用setw或tab在列中正确输出?

C++ 如何使用setw或tab在列中正确输出?,c++,C++,在输出summ之前,您没有使用任何字段宽度控件(即nosetw())。。。在这之后,行中的偏移量是可变的,现在让其他字段对齐已经太晚了。只需有条不紊地处理输出语句,可能会在语句中插入一个“|”或其他字符,向您显示输出的每个部分添加了多少右侧填充,这样您就可以集中精力让它们先对齐,然后在字段宽度正确后删除它们。您没有设置summ的参数宽度 0.00673795 Value True error Approximate error 1 147

在输出
summ
之前,您没有使用任何字段宽度控件(即no
setw()
)。。。在这之后,行中的偏移量是可变的,现在让其他字段对齐已经太晚了。只需有条不紊地处理输出语句,可能会在语句中插入一个
“|”
或其他字符,向您显示输出的每个部分添加了多少右侧填充,这样您就可以集中精力让它们先对齐,然后在字段宽度正确后删除它们。

您没有设置
summ
的参数宽度

0.00673795
Value           True error          Approximate error
1           14741.3         100
-4          59465.3         125
8.5         126051          147.059
-12.3333            183143          168.919
13.7083         203350          189.97
-12.3333            183143          211.149
9.36806         138934          231.653
-6.13294            91120.8         252.75
3.55518         52663.6         272.507
-1.8271         27216.6         294.58
0.86404         12723.5         311.461
-0.359208           5431.12         340.54
0.150479            2133.3          338.71
-0.0455546          776.09          430.326
0.0244573           262.978         286.262
0.00111998          83.378          2083.73
0.00841288          24.8582         86.6873
0.00626791          6.97596         34.2215
0.00686374          1.86688         8.68077
0.00670694          0.460185            2.33782

std::cout那么我该如何解决这个问题:coutsame。设置
值的宽度
,因为将其发送到流。
0.00673795
Value           True error          Approximate error
1           14741.3         100
-4          59465.3         125
8.5         126051          147.059
-12.3333            183143          168.919
13.7083         203350          189.97
-12.3333            183143          211.149
9.36806         138934          231.653
-6.13294            91120.8         252.75
3.55518         52663.6         272.507
-1.8271         27216.6         294.58
0.86404         12723.5         311.461
-0.359208           5431.12         340.54
0.150479            2133.3          338.71
-0.0455546          776.09          430.326
0.0244573           262.978         286.262
0.00111998          83.378          2083.73
0.00841288          24.8582         86.6873
0.00626791          6.97596         34.2215
0.00686374          1.86688         8.68077
0.00670694          0.460185            2.33782
std::cout << std::right 
          << std::setw(10) << summ
          << std::setw(10) << true_error
          << std::setw(10) << approx_error << std::endl;