I need to basically flash a set of numbers for roughly 2 seconds. The user will then have to remember the numbers and type them. How can I do this? I have tried to use a timer or changing the color of the text to the same color of the background, but I can't think of a better way of doing so. Any suggestions?
Asked
Active
Viewed 97 times
0
-
Possible duplicate of [How do I clear ONLY ONE LINE of cmd?](https://stackoverflow.com/questions/42450295/how-do-i-clear-only-one-line-of-cmd) – phuclv Dec 08 '17 at 01:25
-
Possibly even a way of clearing the screen temporarily? – zhodges10 Dec 08 '17 at 01:26
-
you can call `system("cls")` to clear cmd – apple apple Dec 08 '17 at 01:44
1 Answers
0
You have basically three ways of handling this, because typical terminals don't have have the concept of a "screen", just lines.
- Use carriage return or backspace characters to overwrite previous characters with blank spaces (but note the user can hit Enter to "preserve" the data in this case).
- Print out a bunch of empty lines afterwards, but the user can scroll back.
- Use a
curses
library of some kind (probablyncurses
).
You'll need to look at the choices and see which is the best fit for exactly what you are trying to achieve.

Jack Zhou
- 167
- 1
- 2
-
Could you explain how to use "\r"? I am looking into it and I tried to print this: 'cout << "Hello\rDone" << endl;' but it displays 'doneo'? – zhodges10 Dec 08 '17 at 01:38
-
1`\r` returns the "cursor" to the start of the line, so it overwrites the first four characters of "Hello" with "done", which is why you get "doneo". You would need to print empty spaces to cover up the rest of the line. – Jack Zhou Dec 08 '17 at 01:42
-