在Linux中用C ++代码清除终端 [英] Clearing terminal in Linux with C++ code

查看:1248
本文介绍了在Linux中用C ++代码清除终端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我一直在研究如何做到这一点,但说我正在运行一个程序,在终端上有一大堆输出,我如何清除屏幕从我的程序,以便我可以保持我的程序运行?



我知道我可以在终端输入清除,它清除得很好,但就像我说的,对于这个程序,它会对我更有利。 p>

我发现了一些有用的东西,但我不知道是什么或它做什么。

  cout<< \ 033 [2J\033 [1; 1H; 

这可行,但我不知道是什么,如果你能解释它,非常感谢。

解决方案

这些是ANSI转义码。第一个( \033 [2J )从上到下清除整个屏幕( J c $ c> 2 )。第二个代码( \033 [1; 1H )将光标置于行 1 <>



所有ANSI转义都以 ESC [具有由; 分隔的零个或多个参数,并以命令字母( J H )结尾。 \033 是转义字符的C样式八进制序列。



请参阅此处查看完整路演。


Okay, I have been researching on how to do this, but say I am running a program that has a whole bit of output on the terminal, how would I clear the screen from within my program so that I can keep my program running?

I know I can just type clear in terminal and it clears it fine, but like I said, for this program it would be more benefitial for me.

I found something that works, however, I'm not sure what it is or what its doing.

cout << "\033[2J\033[1;1H";

That works but I have no clue what it is, if you could explain it, than I would much appreciate it.

解决方案

These are ANSI escape codes. The first one (\033[2J) clears the entire screen (J) from top to bottom (2). The second code (\033[1;1H) positions the cursor at row 1, column 1.

All ANSI escapes begin with the sequence ESC[, have zero or more parameters delimited by ;, and end with a command letter (J and H in your case). \033 is the C-style octal sequence for the escape character.

See here for the full roadshow.

这篇关于在Linux中用C ++代码清除终端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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