如何清除与\\ X1B [2J屏幕? [英] How to clear the screen with \x1b[2j?

查看:998
本文介绍了如何清除与\\ X1B [2J屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何实施 clrscr()?谷歌搜索它,我发现, \\ X1B [2J 可用于清除屏幕,但我们如何使用它呢?

How do we implement clrscr()? Googling it I found that \x1b[2j can be used to clear the screen but how do we use it?

推荐答案

标准C库不提供清除屏幕的方式。你需要一个操作系统相关的库这一点。

The standard C library doesn't provide a way of clearing the screen. You need an operating-system-dependent library for that.

在DOS和Windows,在DOS或Windows控制台运行的程序,您可以使用随OS的核心C库提供的DOS / Windows扩展名:

Under DOS and Windows, for a program running in a DOS or Windows console, you can use the DOS/Windows extensions provided in the core C library shipped with the OS:

#include <conio.h>
clrscr();

在UNIX系统上,可以使用诅咒库,它提供与操作系统。 curses库的端口,用于大多数操作系统,包括Windows存在,所以这是一个便携式的程序要走的路。与 -lcurses 链接程序和使用

#include <curses.h>
erase();

一些终端和终端仿真器执行特殊功能,如清除屏幕当他们收到一个转义序列。多数终端遵循ANSI标准,它定义了一些转义序列; \\ X1B [2J是这样的序列,其作用是清除屏幕。注资本Ĵ。在这样的终端,的fputs(\\ X1B [2J,标准输出)清除屏幕。这实际上是什么诅咒库的确,当你调用擦除()这样的终端上;诅咒库包括终端类型的数据库,以及对各类用什么转义序列。

Some terminals and terminal emulators perform special functions such as clearing the screen when they receive an escape sequence. Most terminals follow the ANSI standard which defines a number of escape sequences; "\x1b[2J" is such a sequence, and its effect is to clear the screen. Note the capital J. On such a terminal, fputs("\x1b[2J", stdout) clears the screen. This is in fact what the curses library does when you call erase() on such a terminal; the curses library includes a database of terminal types and what escape sequences to use on the various types.

这篇关于如何清除与\\ X1B [2J屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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