Hey,
Usually when I write a program with no GUI, the output and user input remains on the screen of the CMD for the duration of the program. How can I control the amount of time that the output remains on the screen?
Can I make my output disappear after a few seconds?
Can I make the user input disappear from the screen after he clicks enter?
Can I put a delay on an output?
Thanks!
there are libraries and extensions to do all kinds of stuff to the console as well.
All these things are easy with those; some of these can be done without.
I havent felt like doing fancy console in a very, very long time... it was a big deal when I first started and the idea of a gui was new.
A few handy ones you can get for windows (cause you said cmd)
- getch (read a char without showing what was typed)
- gotoxy (move cursor position, one example is back to the start of the current line where you can write spaces over what was just typed... and it 'vanishes')
-there is a clear screen
and more
the portable one is from unix, called ncurses, but there is a windows version so you can use it too.
> Can I make my output disappear after a few seconds?
> Can I make the user input disappear from the screen after he clicks enter?
> Can I put a delay on an output?
You can try this. (Note that this will clear the entire screen and position the cursor at 0,0)
Thank you guys so much!
I just had a ton of much fun playing around with the info you gave me!
Also, I would like to thank the three of you for always taking the time to answer my questions (I noticed that the three of you seem to always manage to solve my questions. thanks guys)
JLBorges, I love the code you that you gave me. It was exactly what I was looking for. Thank you so much for taking the time to write it for me.
Regarding line 22 (std::cout << txt << std::flush ;) , I had trouble understanding what std::flush does. Would you be able to explain what that output does (If Handy Andy or jonnin can explain that output that would also be great, I'm assuming you guys also understand what that means)?
> Regarding line 22 (std::cout << txt << std::flush ;) , I had trouble understanding what
> std::flush does. Would you be able to explain what that output does
This manipulator may be used to produce an incomplete line of output immediately, e.g. when displaying output from a long-running process, logging activity of multiple threads or logging activity of a program that may crash unexpectedly. An explicit flush of std::cout is also necessary before a call to std::system, if the spawned process performs any screen I/O https://en.cppreference.com/w/cpp/io/manip/flush