PDA

View Full Version : the dreaded CLEAR SCREEN function...



dbaryl
12-05-2001, 06:41 PM
OK, just don't kill me for this... I just looked at the FAQ board, and someone suggests to use
#include <stdlib.h>

system ("cls"); for clear screen... however, below there's a post that says:


adrianxw wrote:
>>> system ("cls");

Then read the FAQ to find out why this is a bad idea.

I read the Board FAQ (http://cprogramming.com/boardfaq.html#clear) to find why thats wrong, but it isn't there... In fact, the system ("cls"); isn't on the BoardFAQ at all...

:confused: :confused: :confused: :(

lightatdawn
12-05-2001, 06:50 PM
I thought there was a system("cls"); example in the FAQ too, until i looked (and i compiled the bloody thing). Apparently adrianxw was reffering to the comments about the use of system in the Running Execs segment of the FAQ. The fact of the matter is, system() isnt really something your ever likely to need. It loads up your command processor and it, in turn, executes the argument you passed to system(). Its slow. Veeery slow. Besides... Theres always another way. ... ... *ahem* Couldn't resist.

Flarelocke
12-05-2001, 07:33 PM
1)system("cls") is a very platform dependent way to do it. It will only work on MS-DOS.

2)It's slow as hell

As a practical matter, you could use numerous \n's(platform independent) or simply use the clrscr() function in conio.h (which is almost as platform specific as system("cls"))

gnu-ehacks
12-05-2001, 09:00 PM
>>you could use numerous \n's(platform independent)

How is that platform dependant? All you have to do is ensure that you have enough \n's to get past any screen that you may encounter. Not too platform dependant.

dbaryl
12-05-2001, 09:45 PM
>>clrscr() function in conio.h

I just tried that, but it doesn't work for M$ VC++.... I'm assuming that you just put the #define <conio.h> up on top and clrscr(); inside the main, right?

If that really doesn't work, what is the BEST way of getting the clear_screen then? (for Visual C++ compiler).

Thanks

DeViLs_SouL
12-05-2001, 10:26 PM
no man. your having a syntax error. u go:

#include <conio.h>
#include <iostrem.h>
#include <stdlib.h>
#include <stdio.h>
.
.
.

main(){
int variable_1;
char what_ever;

cout<<"hello";

whatever....

clrscr();


}


hope u got it....

oskilian
12-05-2001, 11:59 PM
but clrscr() isn't ANSI, so I guess that the only clean way to clear the screen is doing 50 printf("\n");'s

Oskilian

doubleanti
12-06-2001, 12:48 AM
get to the b800:0000 and free your Soul!!! [and, for you non text more graphical tech visionaries, Linear Frame Buffer to the resque!!!!]

nvoigt
12-06-2001, 01:16 AM
The windows way to clear a console window is to write your own ClrScrn function and use that. How to ? Well, read the FAQ.

adrianxw
12-06-2001, 03:37 AM
>>>
adrianxw wrote:
>>> system ("cls");

Then read the FAQ to find out why this is a bad idea.
<<<

As someone has pointed out, it was the use of the system() function I was commenting on. There are ways to clear the screen in the FAQ, (I have absolutely no idea I have typed that short phrase!).

http://www.cprogramming.com/boardfaq.html#execs