是否可以使用 CR 之类的东西一次刷新两行文本? (C++)

发布于 2024-08-16 14:53:22 字数 116 浏览 5 评论 0原文

现在,我正在开发一个控制台应用程序,它应该以给定的时间间隔向控制台显示和更新信息。我遇到的问题是,使用回车符时,我一次只能更新一行文本。如果我使用换行符,则无法再使用回车符更新旧行。

我在这里能做什么?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

∞琼窗梦回ˉ 2024-08-23 14:53:22

您也许能够找到适用于您的平台的curses 库变体。

You might be able to find a curses library variant that works on your platform.

才能让你更想念 2024-08-23 14:53:22

正确的答案是使用 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.

陌若浮生 2024-08-23 14:53:22

这是一个非常丑陋的解决方案,但在紧要关头,你总是可以完全清除控制台,然后重新打印所有内容。在某些情况下,这种策略看起来有点难看;它可能会让事情看起来很眨眼。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文