Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ragadast

How do you clean the screen?

This topic is 5915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
quote:
Original post by Rickmeister
Yet another ugly way to clear the console...


#include <iostream.H> // muahahahaha

void 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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!