• Advertisement

Archived

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

very easy question

This topic is 5943 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 I clear my dos-screen in c++ and wich file do I have to include I use MS vc++ thanx in advance

Share this post


Link to post
Share on other sites
Advertisement
the C++ way (thats how I think of it anyways) is including
stdlib.h
and using the function:
system("CLS");

Never forget, All your base are belong to us!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Actually, making system calls like that is a complete hack. To do a clear screen professionally, you need to utilize the windows API. There are functions that were made specifically for this purpose. You need to basically clear the text buffer of the console application. Look up the console functions at MSDN. Its more complicated that a system call such as system("cls");, but, its a better way to do things.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks for the info, helped me too Anyone know (or care to explain) why the conio.h function clrscr() won''t work in MS VC++?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
conio is compiler and system specific, it is not part of the c++ standard lib therefore the compiler manufacturers have different conio headers. Because different systems require different ways of accessing the video, there is no standard way to clear a console app. Clearing the screen is not in any way standard across any platform, therefore there are many ways to do it. For a windows console just use the windows API.
  

void clearscreen( HANDLE hConsole )
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */
DWORD dwConSize;
GetConsoleScreenBufferInfo( hConsole, &csbi );
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

FillConsoleOutputCharacter( hConsole, (TCHAR) '' '',
dwConSize, coordScreen, &cCharsWritten );

GetConsoleScreenBufferInfo( hConsole, &csbi );

FillConsoleOutputAttribute( hConsole, csbi.wAttributes,
dwConSize, coordScreen, &cCharsWritten );

SetConsoleCursorPosition( hConsole, coordScreen );
return;
}
//Clears the screen

void clrscr()
{
clearscreen(GetStdHandle(STD_OUTPUT_HANDLE));
return;
}



maybe this helps, idunno, be sure to include windows.h, etc.

Share this post


Link to post
Share on other sites

  • Advertisement