I need to get input from the user but if an invalid argument is passed in then the "Invalid" messages stack up.
I'd prefer if it just kept printing the invalid on the same line and then once a correct input is given it resets the line to original question.
I've seen the talk of using \r but it does not seem to work for me.
bool getInput(std::variant<std::string, float>* toOut, bool* restart, bool* qUsed){
std::string userIn;
std::cin >> userIn;
if(userIn == SENTINAL){
*restart = true;
return false;
}
try {
*toOut = std::stof(userIn);
} catch(std::invalid_argument) {
if(userIn == TO_SOLVE && !*qUsed){
*toOut = TO_SOLVE;
*qUsed = true;
} else {
std::cout << "\rInvalid, please try again : ";
getInput(toOut, restart, qUsed);
}
}
return true;
}
I haven't put the resetting to original question yet.
When I run this the \r does nothing.
Why is this / what's the best way to "update" cmd text?