#include <iostream> #include <string> #include <cctype> using namespace std; int main() { string passCode; passCode = "1 "; int i; for(i =0; i < passCode.length();i++){ if(isspace(passCode.at(i)) == true){ passCode.replace(i,1,"_"); } } cout << passCode << endl; return 0; } Code above, my directions are to [Replace any space ' ' by '_' in 2-character string passCode. If no space exists, the program should not print anything.]
with my code currently the way it is, it outputs "1 ". When i run it with the condition checking for false instead of true, it prints "_ ". I am not getting why its doing this, anyone see the problem that i don't? I am not allowed to use the algorithm. header. I am also only allowed to work within main, no functions or imported headers/classes.