#include <iostream>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
//using std::setw;
int main()
{
char cEnd;
char ch;
double dh;
cout << "Please input any key to set ch; " <<endl;
cin >> ch;
dh = static_cast<double>(ch);
cout << "dh = static_cast<int>(ch);" << endl;
cout << "dh = " << dh <<endl;
//for endl;
cout << "Please input any key to endl;" <<endl;
cin >> cEnd;
cout << cEnd << endl;
return 0;
}
本文介绍了一个简单的C++程序,该程序演示了如何将字符输入转换为双精度浮点数,并展示了如何使用C++标准库iostream和iomanip进行基本的输入输出操作。通过静态类型转换函数static_cast, 字符被转换成其对应的ASCII数值并作为双精度浮点数显示。

被折叠的 条评论
为什么被折叠?



