I want to show a progress bar (like wget) how do i keep writing to the last line in the console?
我想显示一个进度条(比如wget),我如何一直写到控制台的最后一行?
Windows 7 vis 2005 c++
Windows 7 vis 2005 c++
2 个解决方案
#1
16
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.
有了carriage-return(“\r”),您可以跳到当前行的开头。这只适用于支持此特性的终端。
After you jumped back you can just print your new status-line.
在您跳回去之后,您可以打印您的新状态线。
#2
7
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.
如果您需要回到上一行,并使用本机Win API,您可以在kernel32.lib中使用setcomfort ecursorposition方法。
Edit: GnuWin32 also seems to have a ncurses port if you can live with the dependencies on GnuWin32.
编辑:如果您可以使用GnuWin32上的依赖项,GnuWin32似乎也有一个ncurses端口。
#1
16
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.
有了carriage-return(“\r”),您可以跳到当前行的开头。这只适用于支持此特性的终端。
After you jumped back you can just print your new status-line.
在您跳回去之后,您可以打印您的新状态线。
#2
7
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.
如果您需要回到上一行,并使用本机Win API,您可以在kernel32.lib中使用setcomfort ecursorposition方法。
Edit: GnuWin32 also seems to have a ncurses port if you can live with the dependencies on GnuWin32.
编辑:如果您可以使用GnuWin32上的依赖项,GnuWin32似乎也有一个ncurses端口。