C++:使用错误 C4700 未初始化的局部变量""
C++: Error C4700 uninitialized local variable " " used
我正在尝试创建一个程序,该程序接受 3 个数字并按升序排列。
我已经写出了代码,但不断收到错误说:
"错误 C4700 使用未初始化的局部变量"num2"。
"错误 C4700 未初始化的局部变量 "num3" 使用。
我之前做过 If/if-else/else 嵌套,但我从未遇到过此错误。我是C++新手,仍在学习。
我尝试将变量设置为默认值为 0,然后要求输入一个数字,以便将其覆盖,然后我可以将它们相互比较。当我不将它们设置为 0 时,我也会收到一个随机运行时错误;
这是代码:
#include <iostream>
using namespace std;
int main()
{
int num1; //I get an error message when I do not set it to 0.
int num2;
int num3;
cout << "Please enter three numbers: " << endl;
cin >> num1; num2; num3;
if (num1 > num2 && num2 > num3){
cout << "In ascending order: " << num1 << num2 << num3 << endl;
}
else if (num2 > num1 && num1 > num3)
{
cout << "In ascending order: " << num2 << num1 << num3 << endl;
}
else if (num3 > num1 && num1 > num2){
cout << "In ascending order: " << num3 << num1 << num2 << endl;
}
else
{
cout << "There was an invalid input." << endl;
}
system("pause");
return 0;
}
这是我遇到的错误。
cin >> num1; num2; num3;
这可能应该是
cin >> num1 >> num2>> num3;
其他一些评论:
1)避免"使用命名空间标准;"
2)尝试找到一个更高效C++开发环境,不会强迫您浪费时间解决诸如系统之类的愚蠢问题("暂停")
相关文章:
- 未初始化的变量有什么危险
- 使用的未初始化局部变量'Quick'
- C++如何通过"constructor initialization"初始化行变量?
- "local scope"中的 C++ 初始化静态变量
- 为什么我的 c++ 程序检查不是初始化的变量?
- 使用大括号或括号初始化成员变量
- 使用 std::ios_base::Init 正确初始化全局变量
- 'auto *x = new some_struct{};"是一个未初始化的变量?
- 是否可以将已经初始化的变量转换为 void*?
- Clang++ 6.0 内存清理器未报告返回值指示条件分支的函数中的未初始化局部变量
- 为什么默认情况下初始化局部变量
- 如果仅在 lambda 中使用,则不会在发布版本中初始化局部静态变量
- 对初始化时使用的未初始化局部变量感到困惑
- 如何在Qt(gcc 64位)中禁用自动初始化局部变量
- 在函数中初始化局部变量时出现问题
- 为什么VS编译器不会在C++上自动初始化局部变量?
- C++构造函数:在初始化器列表之前初始化局部变量
- 如何初始化局部联合变量
- 实际初始化的未初始化局部变量
- 收到未初始化局部变量的警告