very easy question

Started by
6 comments, last by da_cobra 22 years, 6 months ago
how do I clear my dos-screen in c++ and wich file do I have to include I use MS vc++ thanx in advance
Advertisement
include the file
conio.h
and use the functuin
clrscr();
The Department of Next Life - Get your Next-Life Insurance here!
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!
clrscr() using conio.h wont work with MSVC++. Try SirSmoke''s method.
just :
system("CLS");

works

didn''t even had to include stdlib.h

thanx for the response
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.
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++?
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.

This topic is closed to new replies.

Advertisement