What function in C++ puts string into console, with ability edit? I have such state of console:
After work of needed function I want to see this:
but not this:
It cannot be done natively on the terminal, you have to do it in your control flow.
A little example
string text("Hello, World")
cout << text;
char x = getch();
while (x != '\n') { //loop breaks if you press enter
if (x == 127 || x == 8) { //for backspace(127) and delete(8) keys
cout << "\b \b"; //removes last character on the console
text.erase(text.size() - 1);
}
else {
cout << x;
text.append(x);
}
x = getch();
}
"\b"
is nondestructive backspace. i.e it moves the cursor backwards but doesn't erase.
"\b \b"
is destructive backspace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With