是否可以使用 CR 之类的东西一次刷新两行文本? (C++)
现在,我正在开发一个控制台应用程序,它应该以给定的时间间隔向控制台显示和更新信息。我遇到的问题是,使用回车符时,我一次只能更新一行文本。如果我使用换行符,则无法再使用回车符更新旧行。
我在这里能做什么?
Right now, I have a console application I'm working on, which is supposed to display and update information to the console at a given interval. The problem I'm having is that with a carriage return, I can only update one line of text at a time. If I use a newline, the old line can no longer be updated using a carriage return.
What can I do here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您也许能够找到适用于您的平台的curses 库变体。
You might be able to find a curses library variant that works on your platform.
正确的答案是使用 Mark 提到的curses 库。但是,如果您使用的是类 Unix 系统并且不愿意被诅咒所困扰,那么快速而肮脏的解决方案是直接打印出 vt100 转义序列:
http://ascii-table.com/ansi-escape-sequences-vt-100.php
我经常这样做,尤其是在脚本语言中没有诅咒绑定。
The correct answer is to use the curses library as mentioned by Mark. But if you're on Unix-like systems and can't be bothered with curses then the quick and dirty solution is to directly print out vt100 escape sequences:
http://ascii-table.com/ansi-escape-sequences-vt-100.php
I often do this especially in scripting languages that doesn't have a curses binding.
这是一个非常丑陋的解决方案,但在紧要关头,你总是可以完全清除控制台,然后重新打印所有内容。在某些情况下,这种策略看起来有点难看;它可能会让事情看起来很眨眼。
This is a really ugly solution, but in a pinch you could always just clear the console entirely and then reprint everything. This strategy looks a bit ugly in some cases; it may make things look blinky.