Does today's C or C++ compilers use the clrscr
system function?
5 Answers
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). However some compilers (like Turbo C/C++) support it as an extension.

- 30,738
- 21
- 105
- 131

- 91,295
- 49
- 239
- 345
-
so what we use in linux instead of clrscr – dom Aug 08 '15 at 10:27
Like all of the stuff in 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, ...
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>
. 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.

- 208,859
- 35
- 376
- 711
-
1`conio.h` is (apart from using the native API functions directly) the only way to get reliable Unicode input and output for the Windows console, so it still plays a role today. – Philipp Jul 12 '10 at 12:25
-
Isn't it possible to set the console io 'codepage' to UTF-8? I don't it's not possible to set the 'ANSI codepage' to UTF-8 but I thought Windows allowed UTF-8 in other contexts. – R.. GitHub STOP HELPING ICE Jul 12 '10 at 12:49
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. In particular, it provides the clear()
function with a similar functionality to the clrscr()
function you mentioned. For Windows (which must be your case), there is PDCurses that employs the same API. In particular, ncurses
complies with the XSI Curses base specification, and it is widely adopted; you should stick to it if any degree of portability matters.

- 4,882
- 2
- 29
- 55
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 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().

- 106,608
- 13
- 126
- 198
On Unix-like systems you can use VT100 escape codes.
std::cout << "\033[2J" << std::flush;

- 20,267
- 14
- 135
- 196