• ### Announcements

#### Archived

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

# very easy question

## 7 posts in this topic

how do I clear my dos-screen in c++ and wich file do I have to include I use MS vc++ thanx in advance
0

##### Share on other sites
include the file
conio.h
and use the functuin
clrscr();
0

##### Share on other sites
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!
0

##### Share on other sites
clrscr() using conio.h wont work with MSVC++. Try SirSmoke''s method.
0

##### Share on other sites
just :
system("CLS");

works

didn''t even had to include stdlib.h

thanx for the response
0

##### Share on other sites
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.
0

##### Share on other sites
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++?
0

##### Share on other sites
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 screenvoid clrscr(){ clearscreen(GetStdHandle(STD_OUTPUT_HANDLE)); return;}

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