WhiteSpace Replace Runtime Error

I'm stuck on a problem in Zybooks, the goal is to take a 2-character string input and replace any white space with an underscore. I'm pretty sure I'm on the right track but something is obviously wrong because I'm getting a run-time error

#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main() {
string passCode;

passCode = "1 ";

if(isspace(passCode.at(0))){
passCode.replace(passCode.at(0),1,"_");
}
if(isspace(passCode.at(1))){
passCode.replace(passCode.at(1),1,"_");
}
cout << passCode << endl;
return 0;
}
note: Zybooks changes the passcode string when testing
yeah it worked thanks!
Topic archived. No new replies allowed.