简体   繁体   English

函数clrscr在C和C ++中

[英]Function clrscr in C and C++

今天的C或C ++编译器是否使用clrscr系统函数?

clrscr() is a nonstandard function (neither mentioned in ISO C99 nor in ISO C++-98 ) defined in <conio.h> (which is not standard compliant itself). clrscr()<conio.h>定义的非标准函数(在ISO C99ISO C++-98都没有提到)(它本身不符合标准)。 However some compilers (like Turbo C/C++ ) support it as an extension. 但是一些编译器(如Turbo C / C ++ )支持它作为扩展。

Like all of the stuff in conio.h . 就像conio.h所有内容一样。 clrscr() has nothing to do with standard C. conio is a common API of ancient DOS-based C implementations for lower-level console io - things like clearing the screen, moving the cursor, reading individual keystrokes, etc. I don't know the history but presumably it dates back to before DOS had ANSI.SYS to support standard terminal-escape codes for cursor positioning, clearing the screen, changing colors, ... clrscr()与标准C无关。 conio是基于DOS的低级控制台的基于DOS的C实现的常见API,例如清除屏幕,移动光标,读取单个按键等等。我不知道知道历史,但可能它可以追溯到DOS之前有ANSI.SYS支持光标定位的标准终端转义码,清除屏幕,改变颜色,......

If you're just playing around learning C, there's no harm in using the conio functions, but you should avoid making a habit of #include <conio.h> . 如果你只是在玩学习C,使用conio函数没有坏处,但你应该避免养成#include <conio.h>的习惯。 In most of the questions I've seen on SO where conio.h was included, it wasn't even being used... This kind of bad habit leads to senselessly nonportable code. 在我所看到的大多数问题中,其中包含了conio.h ,它甚至没有被使用......这种坏习惯导致无意义的非便携代码。

Also, as an alternative to conio.h , you can try using ncurses , which provides terminal handling, cursor management, colors and a lot of other functionalities. 此外,作为conio.h的替代方案,您可以尝试使用ncurses ,它提供终端处理,游标管理,颜色和许多其他功能。 In particular, it provides the clear() function with a similar functionality to the clrscr() function you mentioned. 特别是,它为clear()函数提供了与你提到的clrscr()函数类似的功能。 For Windows (which must be your case), there is PDCurses that employs the same API. 对于Windows(必须是您的情况), PDCurses使用相同的API。 In particular, ncurses complies with the XSI Curses base specification, and it is widely adopted; 特别是, ncurses符合XSI Curses基本规范,并且被广泛采用; you should stick to it if any degree of portability matters. 如果任何程度的便携性很重要,你应该坚持下去。

DeathStation 9000 and its ZOG C compiler still use clrscr() . DeathStation 9000及其ZOG C编译器仍然使用clrscr()

quote from http://dialspace.dial.pipex.com/town/green/gfd34/art/ 来自http://dialspace.dial.pipex.com/town/green/gfd34/art/

It would be unfortunate if any more lives were lost simply because some programmers feel a deep spiritual need to obliterate the display device, and much much more, using ZOG C's Commence Launch (Remote Systems Console Request) function, clrscr() . 如果因为一些程序员感到需要消除显示设备的精神需求,以及更多,使用ZOG C的Commence Launch(远程系统控制台请求)函数clrscr() ,那将是更多的生命丢失将是不幸的。

On Unix-like systems you can use VT100 escape codes. 在类Unix系统上,您可以使用VT100转义码。

std::cout << "\033[2J" << std::flush;

See http://www.termsys.demon.co.uk/vtansi.htm http://www.termsys.demon.co.uk/vtansi.htm

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

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