我的简单if-else语句是如何无法访问的代码
How is my simple if-else statement unreachable code?
老实说,我收到一个错误,我很震惊。我是CS专业的大三学生,我无法让这个简单的程序发挥作用。Clion说这两条线是无法到达的,但我的测试用例似乎可以工作。
代码:
#include <iostream>
#include <string>
using namespace std;
int main() {
string s = "";
while(s != "|") {
int val1 = 0;
int val2 = 0;
cin >> val1;
cin >> val2;
if(val1 == val2) {
cout << "the numbers are equal.n";
} else {
cout << "the smaller value is: " << min(val1, val2) << 'n'; // Says these two
cout << "the larger value is: " << max(val1, val2) << 'n'; // lines are unreachable
}
cin >> s;
}
return 0;
}
测试用例:
3 3
the numbers are equal.
f
4 5
the smaller value is: 4
the larger value is: 5
|
Process finished with exit code 0
如果这个代码是如此的不可访问,我的程序为什么会访问它?
CLion 可能有一些问题
这个引起了我的注意:
你检查字符串是否等于聊天数组,这可能会在运行时得到解决,但代码检查器不喜欢。尝试使用:
char s;
while(s!='|') {...}
除此之外,我不知道。。。
它可能没有预测到变量的变化,尝试使用volatile关键字?这可能会有所帮助。。。这仍然是一个bug。
相关文章:
- 无法访问嵌套类.类的使用无效
- 我的简单if-else语句是如何无法访问的代码
- C++:无法访问声明的受保护成员
- 为什么此派生对象无法访问基类的后递减方法?
- 友元函数无法访问私有数据成员 (c++)
- 为什么我的好友类无法访问私人会员?
- 为什么 std::itrator 无法访问该函数
- 为什么即使我声明了朋友类,我也会收到错误"无法访问类中声明的私人成员"
- C++ 传递指向对象的指针的指针,无法访问成员
- 使公共数据成员在C++中无法访问
- 为什么我无法访问指向数组中成员函数的指针?
- 类无法访问自己的私有静态 constexpr 方法 - Clang bug?
- 无法访问的代码 在 C++11 中,可能导致这种情况的原因是什么?
- 类成员函数无法访问同一类的私有结构节点?
- OpenCV C++:当垫子类型未知时无法访问垫子元素?
- 特里树.无法访问内存
- 从纯虚拟类 (A) 派生的指针无法访问来自纯类 (B) 的重载方法
- 无法访问基类函数 C++
- 调用函数后无法访问数组
- 好友功能 - 成员无法访问