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

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

问题描述

好的,我一直在研究如何做到这一点,但假设我正在运行一个在终端上有大量输出的程序,我将如何从我的程序中清除屏幕以便我可以保留我的程序跑步?

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?

我知道我可以在终端中输入 clear 并且它可以很好地清除它,但就像我说的那样,对于这个程序,它对我更有益.

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 beneficial for me.

我发现了一些有用的东西,但是,我不确定它是什么或它在做什么.

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

cout << "33[2J33[1;1H";

这可行,但我不知道它是什么,如果您能解释一下,我将不胜感激.

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

推荐答案

这些是 ANSI 转义码.第一个 (33[2J) 从上到下 (2) 清除整个屏幕 (J).第二个代码 (33[1;1H) 将光标定位在行 1,列 1.

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

所有 ANSI 转义符都以序列 ESC[ 开头,有零个或多个由 ; 分隔的参数,并以命令字母 (JH 在你的情况下).33 是转义字符的 C 风格八进制序列.

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). 33 is the C-style octal sequence for the escape character.

请参阅此处了解完整路演.

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

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