【发布时间】:2017-03-04 18:30:22
【问题描述】:
我错误地在执行以下代码块时发现了该场景
#include <iostream>
using namespace std;
int main()
{
int input1;
float input2;
cout << "Enter a real number :";
cin >> input1;
cout << "The int number is " << input1 << endl;
cout << "Enter another number :";
cin >> input2;
cout << "The float number is " << input2 << endl;
}
上面的输出是
Enter a real number :a
The int number is -858993460
Enter another number :a
The float number is -1.07374e+08
谁能解释一下如何在内部处理上述情况导致上述情况?
注意 -
- 在 VS2015 中运行上述内容。
由于我是新尝试使用 C++,如果我在此过程中遗漏了任何参考资料,请指出我。
【问题讨论】:
-
什么是
input?它没有在您的示例中声明。 -
你检查过失败位吗 - 它可能不是一个数字
-
@mpiatek 在两种情况下的输入都是'a',对于所有情况,int 和 float 的输出都是相同的,没有任何变化
-
@EdHeal 我不想做失败检查(我知道我应该做)。但我想知道这些相同的价值观是如何在内部产生的。
标签: c++