Hi I have the following code that should echo back each character is entered.
std::string Utils::Input(bool fPassword) {
std::string strInput;
char chInput;
while(chInput != '\n' && chInput != '\r') {
std::cin.get(chInput);
if(chInput == '\t') {
//autocomplete
}
else if(chInput == '\b') {
strInput = strInput.substr(0, strInput.length() -2);
std::cout << chInput;
}
else if(chInput == '\n') {
std::cout << "\n";
}
else {
strInput += chInput;
if(!fPassword)
std::cout << chInput;
else std::cout << "*";
}
}
return strInput;
}
However the characters are only printed altogether when a newline is entered, and not while typing. I understand it might be a buffering issue, but how to solve?
I'am already setting
std::cout.setf(std::ios::unitbuf);
And manually flushing does not help.