I want to show a progress bar (like wget) how do i keep writing to the last line in the console?
Windows 7 vis 2005 c++
How to overwrite an existing line without terminal sequence. The \r or carriage return will put the cursor at the beginning of the line and allows you to overwrite the content of the line.
Writing in Console AppWriteLine() or Console. Write(), basically both methods are used to print output of console.
By using: \n – It prints new line. By using: \x0A or \xA (ASCII literal of \n) – It prints new line. By using: Console. WriteLine() – It prints new line.
WriteLine(Object) Writes the text representation of the specified object, followed by the current line terminator, to the standard output stream. WriteLine(String, Object, Object, Object, Object)
with carriage-return ("\r") you can jump back to the beginning of the current line. This will only work for terminals which have support for this feature.
After you jumped back you can just print your new status-line.
If you need to go back further than the last line and are using native Win API, you can use the SetConsoleCursorPosition method in kernel32.lib.
Edit: GnuWin32 also seems to have a ncurses port if you can live with the dependencies on GnuWin32.
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