How do you clean the screen?

Started by
10 comments, last by Ragadast 22 years ago
How do you clean the screen with C++? I have another question, is VC++ compiler different than Borland C++ one? I tried compiling a console program in VC++ but it didn''t work (working with iostream.h and string.h), and tried compiling with Borland C++ and it worked. What happened?
Advertisement
A program that cleans your screen? That would be awesome! Just kidding, I couldn''t resist As to clearing the screen in console mode I''ve had trouble with that myself...apparently Microsoft doesn''t really want people to write console apps. However it''s probably possible; I usually just print enough blank lines to push everything off the screen.

    #include <conio.h>int main(void){   clrscr();}    


____________________________________________________________
www.elf-stone.com

[edited by - benjamin bunny on May 5, 2002 9:56:50 PM]

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

There is no standard way of clearing the screen.
C++ doesn''t even have a notion of "screen".

Either use platform-dependent libraries (e.g. conio.h as b.bunny pointed out), or ANSI escape sequences.

Yes, VC++ is different from BC++

Finally, don''t use iostream.h but iostream unless you want the Code Police to raid your computer. (iostream.h is a deprecated header for backward compatibility only.)

[Questions (STFW) | GDNet Start Here | GDNet Search | Forum FAQ | Google | Asking Smart Questions ]
[Docs (RTFM) | MSDN | SGI''s STL | OpenGL | File formats]
[C++ Must Haves (RTFS) | MinGW | Boost | Loki | FLTK | SDL ]

Stolen from Magmai Kai Holmlor, who held it from Oluseyi, who was inspired by Kylotan...
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Yet another ugly way to clear the console...

#include <iostream.H> // muahahahahavoid clear_screen(){   system("cls");} 
ms dont mind, its just there is no standard way. search the win32 api for the console functions, all the control you want (including make the console size large, moving the cursor, fill the console up, using different pages, etc.). they give you stupendous control, in fact so much you could do double buffered animation.

also look into ansi codes (make sure ansi.sys is loaded).
There is the code for such a function in MSDN, I''ll copy & paste it in here:

/* Standard error macro for reporting API errors */
#define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \
on line %d\n", __FILE__, GetLastError(), api, __LINE__);}

void cls( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 }; /* here''s where we''ll home the
cursor */
BOOL bSuccess;
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize; /* number of character cells in
the current buffer */

/* get the number of character cells in the current buffer */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "GetConsoleScreenBufferInfo" );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

/* fill the entire screen with blanks */

bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) '' '',
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputCharacter" );

/* get the current text attribute */

bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi );
PERR( bSuccess, "ConsoleScreenBufferInfo" );

/* now set the buffer''s attributes accordingly */

bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );
PERR( bSuccess, "FillConsoleOutputAttribute" );

/* put the cursor at (0, 0) */

bSuccess = SetConsoleCursorPosition( hConsole, coordScreen );
PERR( bSuccess, "SetConsoleCursorPosition" );
return;
}

As parameter u can give GetStdHandle( STD_OUTPUT_HANDLE).
[My Lousy Page | Kings Of Chaos | Vampires | [email=lordlethis@hotmail.com]email.me[/email]]
quote:Original post by Rickmeister
Yet another ugly way to clear the console...

#include <iostream.H> // muahahahahavoid clear_screen(){   system("cls");}  


Maby im wrong, but who ever said we are using Windows/DOS here. Maby we arem but THAT ^ would only work on Wundows/DOS. Maby im worong.

[ my engine ][ my game ][ my email ]
SPAM
Rate me up.
quote:Original post by AfTeRmAtH
Maby im wrong, but who ever said we are using Windows/DOS here. Maby we arem but THAT ^ would only work on Wundows/DOS. Maby im worong.


Actually system(const char*) is ANSI-C standard.. What command you decide to send is OS dependant.. But a wild guess is that Radagast uses Win32..
Isn''t SYSTEM("CLS") a function from stdio.h?

This topic is closed to new replies.

Advertisement