tags:

views:

910

answers:

7

I've looked everywhere for this function and cannot find the header files to make this work. It says clrscr() undeclared which brings me to the question. Is clrscr(); a fuction in C++?

+21  A: 

It used to be a function in <conio.h>, in old Borland C compilers.

It's not a C++ standard function.

Pablo Santa Cruz
Borland did had some pretty good DOS graphics libraries.
Lucas McCoy
Actually, Microsoft C++ still has conio.h, although functions like clrscr() are not there.
Vilx-
+1  A: 

A web search says the header file you want is 'conio.h' - I haven't tried it out, so no guarantees. Its existence may also depend on what platform you are compiling against.

Bruce
A: 

The easiest way to clear the screen in real C++ is to just send out a bunch of blank lines. Of course this is assuming that stdout is directed at the screen and not a file:

for (int i = 0; i < 80; ++i)
     cout << "\n";
cout << endl;
Eclipse
It also assumes that the console line buffer is less than 80 lines, which is not guaranteed.
Euro Micelli
Yup - but if you're worry about "clearing" a screen buffer, usually you know how many lines you're dealing with.
Eclipse
+3  A: 

you have to include this header file for this function

#include <conio.h>
Muhammad Akhtar
+8  A: 

And before someone posts the usual "please email me the conio.h file" request, can I point out that this ancient Borland header file only contained the declaration of the function. You would also need the supporting Borland library, which will not be compatible with any modern C++ compilation system.

anon
+3  A: 

As mentioned before, clrscr() is from turbo c++, inside conio.h

For all intents and purposes, conio.h is "non standard", and as such should be probably avoided.

I tend to use the precompiler to choose what to use for a simple clear screen, and just call the operating system's clear program.... it's smart enough to know how "tall" the screen is.

// somewhere in the program
#DEFINE WINDOWS 1

void console_clear_screen() {
  #ifdef WINDOWS
  system("cls");
  #endif
  #ifdef LINUX
  system("clear");
  #endif
}

In windows, you may want to look at the windows.h, You can interact with the windows console directly using a "handle", often noted in code as an hWin.

In linux, i've had good luck with curses/ncurses, although it is a little confusing at first.

Ape-inago
Isn't #define lowercase? Also the compiler will define WINDOWS or LINUX for you, won't it?
jmucchiello
I don't know if define is case sensitive. and typically that define is included via windows.h as "win32"It was just an example.
Ape-inago
+1  A: 

I used to do borland too.

Investigating curses is a good idea. It works on many unix platforms.

You might take a look at nconio at source forge.

This looks promising as well.

EvilTeach