擦除当前打印的控制台行 [英] Erase the current printed console line

查看:30
本文介绍了擦除当前打印的控制台行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 C 中擦除当前打印的控制台行?我在 Linux 系统上工作.例如 -

How can I erase the current printed console line in C? I am working on a Linux system. For example -

printf("hello");
printf("bye");

我想在同一行打印 bye 代替 hello.

I want to print bye on the same line in place of hello.

推荐答案

您可以使用 VT100 转义码.大多数终端,包括 xterm,都支持 VT100.对于擦除一行,这是^[[2K.在 C 中,这给出了:

You can use VT100 escape codes. Most terminals, including xterm, are VT100 aware. For erasing a line, this is ^[[2K. In C this gives:

printf("%c[2K", 27);

这篇关于擦除当前打印的控制台行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆