简体   繁体   English

用c ++清除屏幕

[英]Clearing the screen in c++

Is their a way to clear the screen in c++ on a mac without using the system("clear"); 他们是一种在不使用系统的情况下在mac上用c ++清除屏幕的方法(“清除”); command? 命令? If not is their a way to replace a character? 如果不是他们替换角色的方法?

If you absolutely do not care about portability, just emit the same sequence of characters that clear does. 如果你完全不关心的可移植性,只是发射出相同的字符序列clear呢。

$ clear | od -c
0000000 033   [   H 033   [   2   J
0000007
$ : "Oh, it is ESCAPE [ H ESCAPE [ 2 J on my computer"
$ cat clear_fun.cc
#include <iostream>
void clear() { std::cout << "\033[H\033[2J" << std::flush; }
$

Standard C++ doesn't talk about a "screen" or something. 标准C ++不会谈论“屏幕”或其他东西。 On UNIXes you can use ncurses. 在UNIX上,您可以使用ncurses。 Generally, this just use terminal control codes. 通常,这只是使用终端控制代码。 Mostly, you can assume that VT100 is the terminal and you can just use the various control codes. 大多数情况下,您可以假设VT100是终端,您可以使用各种控制代码。 How to do it on Windows terminals I don't know. 如何在Windows终端上做到我不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM