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

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

问题描述

如何在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");

我想在同一行上打印再见,代替您好.

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天全站免登陆