保留小数位数 左右对齐
#include<iomanip> 默认左对齐
cout << fixed; cout << (left)<<setw(n)
cout.precision(n);
避免科学计数法 输入ASCII值
#include<iomanip> 在需要输入ASCII值的数据前加上(int/double等)
cout.setf(ios::fixed, ios::floatfield);
任务:
1. 编程实现:输入一个摄氏温度,转换成华氏温度并输出。(提示:摄氏温度=(华氏温度-32)×5/9)。输入输出格式参见样张:
提示: 38.5为输入,其余均为输出。 |
#include<iostream>
using namespace std;
int main()
{
double a, b;
cout << "请输入摄氏温度:";
cin >> a;
b = 1.8*a + 32;
cout << "华氏温度为:" << b