C++中的 setw() 没有像我预期的那样响应
Setw() in C++ isn't responding as I expected
所以下面的代码工作正常,但有一个例外:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
int value1, value2, value3, value4;
float calcMean,calcStDev;
// Input values from keyboard
// prompt user for input
cout << "Enter 1st value. " << endl;
cin >> value1;
cout << "Enter 2nd value. " << endl;
cin >> value2;
cout << "Enter 3rd value. " << endl;
cin >> value3;
cout << "Enter 4th value. " << endl;
cin >> value4;
// Calculate the mean, mean = (value1 + value2 + value3 + value4)/4.0
calcMean = (value1 + value2 + value3 + value4) / 4.0;
// Calculate the standard deviation, standard deviation = squareroot((sum((input value-mean)*(input value-mean)))/number of input value - 1)
calcStDev = sqrt((pow((value1 - calcMean),2) + pow((value2 - calcMean),2) + pow((value3 - calcMean),2) + pow((value4 - calcMean),2))/(4-1));
// Output display
cout << fixed << setprecision(2) << endl;
cout << "Mean of the four values: " << setw(10) << calcMean << endl;
cout << "Standard deviation of the four values: " << setw(10) << calcStDev << endl;
cin.get();
cin.get();
return 0;
}
输出似乎没有像我预期的那样响应 setw()(我希望数字 18.50 直接超过 19.64,一个在另一个之上)。
知道我做错了什么吗?
Enter 1st value.
2
Enter 2nd value.
36
Enter 3rd value.
35
Enter 4th value.
1
Mean of the four values: 18.50
Standard deviation of the four values: 19.64
我认为
问题是字符串文字"Mean of the four values: "
包含嵌入的制表符。要插入空格,您可能按了 TAB 键而不是空格键。
相关文章:
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- C++ 信号和插槽不工作:插槽不响应事件
- NodeJs 服务器充斥着 UDP 广播,不发送响应
- C++关于ENUM的问题。我得到的响应比枚举列表大
- 应用程序在打开的简历中捕获视频后没有响应
- 使用 cpprest (Casablanca) 返回 PDF 响应
- 如何使用 setfill 和 setw 在字符串变量中存储十六进制值
- 是否可以使用 Python csv 阅读器读取使用 C++ std::setw 生成的文件?
- 为什么当通过 TCP 发送的消息速率增加时,请求-响应消息对的延迟会降低?
- 如何使用从处理程序调度的最终回调将响应异步返回给调用方on_read?
- 获取加密的正文响应WinHttp HTTPS
- QtConcurrent - 在发布到 UI 线程的数千个结果中保持 GUI 响应
- 如何在 c++ 的 toString 方法中使用 setw(x) 并将其放入变量或建议中?
- 同步读取多个 TCP 响应
- HTTP 响应格式不正确?
- 如何使用软化工具包从 OPC UA 服务器异步读取操作回调中的数据值响应中获取 NodeId 详细信息
- HTTP帖子,无需等待响应
- 问题导致程序停止响应,并且姓氏未正确打印
- AT 命令响应解析器
- C++中的 setw() 没有像我预期的那样响应