This code should print "something here", but it actually print wrong
void test(){
string str = "";
int count = 0;
if (count > str.length() - 1){
cout << "something here" << endl;
return;
}
cout << "wrong" << endl;
}
But, if I change a little as below, it will print "something here"
void test_2(){
string str = "";
int count = 0;
int last_index = str.length() - 1;
if (count > last_index){ // change to last_index
cout << "something here" << endl;
return;
}
cout << "wrong" << endl;
}
Anyone can help me?