3分钟学会C++中防止条件运算符错误小技巧

下例一切正常:

#include<iostream>
using namespace std;

int main(){
    
    
    int n=10;
    if(10==n){
    
    
        cout<<n<<endl;
    }
    return 0;
}

如果你将if(10 = =n) 写成if(10=n)将会产生错误,调换10和n的顺序能避免你把==写成=。

猜你喜欢

转载自blog.csdn.net/baidu_38495508/article/details/122430504