Click to See Complete Forum and Search --> : Clear console
WP
Dec 20th, 2000, 05:37 AM
How can I clear the text of a console window?
WP
HarryW
Dec 20th, 2000, 06:16 AM
If you're using Borland you can use the clrscr() function, otherwise you could print however many newlines as there are lines on the screen. I don't remember how many that is.
WP
Dec 21st, 2000, 04:54 AM
I'm using C++, so clrscr() doesn't exist.
What you said about inserting a lot of empty strings, does clear the screen, but then when I insert normal text again, it comes at the bottom of the console, and not at the top.
Any other suggestions?
WP
Wynd
Dec 22nd, 2000, 06:36 PM
Try this, put this in your iostream.h file:
#if defined(BORLAND_C)
#include <conio.h>
#define cls() clrscr()
#endif
#if !defined(BORLAND_C)
#include <stdlib.h>
#define cls() system("cls");
#endif
Then whenever you want to clear it, just do cls().
parksie
Dec 22nd, 2000, 06:44 PM
It's never a good idea to alter the system headers. Put it into a header file of your own if you need to use it. Also, this is slightly more elegant:
#include <conio.h>
#include <stdlib.h>
#if defined(BORLAND_C)
#define cls() clrscr()
#elseif
#define cls() system("cls");
#endif
If the files are included unnecessarily it won't make any difference because anything that's not used will be removed by any optimising compiler anyway.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.