c++ - 如何在5之前设置没有值的宽度
问题描述
如何使输出的整个第二行在输出中右对齐?我相信它设置为右对齐,但我觉得在输出五个之前需要一个变量来表示一个空格。如果有人可以尝试运行该程序以查看我正在谈论的输出显示,那么对于阅读此内容的人来说会更有意义。
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
cout<< "Temp | -------------- Wind Speed --------------" <<endl;
for( int w=5; w<=45; w=w+5) {
cout << setw(10) << right << w;
}
cout<< endl;
for (int t=-5; t<=50; t=t+5) {
cout << setw(5)<< right << t;
for(int w=5; w<=45; w=w+5){
cout << setw(10) << right << fixed<< setprecision(1)<< 35.74+(0.6215*t)-35.75*pow(w,0.16)+(0.4275*t*pow(w,0.16));
}
cout<<endl;
}
}
解决方案
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
cout<< "Temp | -------------- Wind Speed --------------" <<endl;
cout << " ";
for( int w=5; w<=45; w=w+5) {
cout << setw(10) << right << w;
}
cout<< endl;
for (int t=-5; t<=50; t=t+5) {
cout << setw(5)<< right << t;
for(int w=5; w<=45; w=w+5){
cout << setw(10) << right << fixed<< setprecision(1)<< 35.74+(0.6215*t)-35.75*pow(w,0.16)+(0.4275*t*pow(w,0.16));
}
cout<<endl;
}
}
推荐阅读
- openssl - 使用主题中的“T”和“uidNumber”属性创建 CSR 时出错
- google-app-engine - Google App Engine - 什么算作前端?
- c++ - 根据分量 1、2(和 3)对空间(2D/3D)向量的向量进行排序
- docker - Docker 工具箱 TLSParameterError
- docker - Docker - 我们可以通过使用 Docker 社区版在容器内运行的应用程序来管理身份验证系统、用户会话和 cookie 吗?
- javascript - Uncaught SyntaxError: Unexpected token ,
- string - 如何将整数转换为没有 0x 的十六进制字符串(Julia 1.0)
- python-2.7 - 无法在另一台计算机上运行可执行文件
- python - 用 python 抓取网页。无法访问 td 元素
- bash - bash 函数使用 stdin 两次