I want to implement a function to read a user input that return a std::string. I also wish to remove the carriage return before returning the string, just in case something goes wrong (has a carriage return).
std::string getInput() {
std::string str = "";
std::cout << "> ";
std::getline(std::cin, str);
if (std::cin.eof()) {
quitGame();
}
str.erase(std::remove(str.begin(), str.end(), '\r'), str.end());
return str;
}
The error comes on the str.erase
, it states no instance of overloaded function
but I believe I have provided enough headers and matched the parameters of the function?
Could someone please help me out? Am I missing anything here?
Aucun commentaire:
Enregistrer un commentaire