Clrscr function in C and C ++

Does the C or C ++ compiler use the clrscr system function clrscr ?

+7
c ++ c
source share
5 answers

clrscr() is a non-standard function (not mentioned in ISO C99 and not in ISO C++-98 ) defined in <conio.h> (which in itself does not comply with the standard). However, some compilers (e.g. Turbo C / C ++ ) support it as an extension.

+13
source share

Like all things in conio.h . clrscr() has nothing to do with the C. conio standard - this is a common API of ancient C DOS implementations for lower-level consoles - such as clearing the screen, moving the cursor, reading individual keystrokes, etc. I don’t know the story, but presumably this dates before DOS has ANSI.SYS for supporting standard terminal exit codes for positioning the cursor, clearing the screen, changing colors, ...

If you just play the C learning process, there is no harm in using the conio functions, but you should avoid the #include <conio.h> habit. In most of the questions I saw on SO where conio.h was included, it wasn’t even used ... Such a bad habit leads to pointlessly intolerable code.

+7
source share

In addition, as an alternative to conio.h you can try using ncurses , which provides terminal processing, cursor control, colors, and many other functions. In particular, it provides a clear() function with similar functionality to the clrscr() function that you mentioned. For Windows (this should be your case) there is PDCurses that uses the same API. In particular, ncurses complies with the basic XSI Curses specification and is widely used; you must adhere to it if any degree of tolerance is important.

0
source share

DeathStation 9000 and its ZOG C compiler still use clrscr() .

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

It would be unfortunate if life were lost simply because some programmers feel a deep spiritual need to erase the display device and much more using the ZOG C Start Launch (Remote Systems Console Request), clrscr () .

0
source share

On Unix-like systems, you can use VT100 escape codes.

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

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

-one
source share

All Articles