I have noticed on several occasions that I may be creating a problem (described below) when I lay my C++ code out as below. While it may not be ideal, I do it to save space sometimes.
I can only show you a small code snipped because the program is quiet large. Hopefully can articulate the problem clearly.
string st= "TestString,"; // I declare a string.
//further down in my code I want to remove the comma as I do below.
// I do it in the below syntax to save space. Ok, maybe not ideal but I did it.
if(st[st.length()-1]==','){st=st.substr(0,st.length()-1);}
cout << "My new string is: " << st << endl;
// I place a line of codeimmediately below my if statement.
The problem is, sometimes the code directly below my one line If Statement follows the logic of the If Statement when I thought that would be reserved for the code only int the { } .
It doesn't always happen but it does happen randomly. When I leave a space between the One Line If Statement and the code below it, the problem goes away.
Is there a common problem I have created here or is this just an unusual anomaly?
Aucun commentaire:
Enregistrer un commentaire