Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function clrscr in C and C++

Tags:

c++

c

Does today's C or C++ compilers use the clrscr system function?

like image 219
dato datuashvili Avatar asked Jul 12 '10 06:07

dato datuashvili


2 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.

like image 122
Prasoon Saurav Avatar answered Oct 25 '22 03:10

Prasoon Saurav


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.

like image 20
R.. GitHub STOP HELPING ICE Avatar answered Oct 25 '22 02:10

R.. GitHub STOP HELPING ICE