Console Clear Screen

Started by
11 comments, last by Laroche 21 years, 6 months ago
How do you clear the screen in Console in c++? Im using VS6
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
Advertisement
SYSTEM("CLS");
or is it
system("cls");
lol anyways system tells the compiler to use like dos commands and in dos you type CLS to clear the screen
and i think to use system() you need stdlib.h or process.h

[edited by - Irrelevant on October 2, 2002 1:09:11 PM]
MSDN Q99261 - HOWTO: Performing Clear Screen (CLS) in a Console Application.

Heh, look at the publication date

Anyway, I wouldn''t recommend system() for such a trivial task. It''s horribly inefficient.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"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

  void clrscr(){  COORD coordScreen = { 0, 0 };   DWORD cCharsWritten;   CONSOLE_SCREEN_BUFFER_INFO csbi;   DWORD dwConSize;   HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);     GetConsoleScreenBufferInfo(hConsole, &csbi);   dwConSize = csbi.dwSize.X * csbi.dwSize.Y;   FillConsoleOutputCharacter(hConsole, TEXT('' ''),                             dwConSize,                              coordScreen,                             &cCharsWritten);   GetConsoleScreenBufferInfo(hConsole, &csbi);   FillConsoleOutputAttribute(hConsole,                             csbi.wAttributes,                             dwConSize,                             coordScreen,                             &cCharsWritten);   SetConsoleCursorPosition(hConsole, coordScreen); }  

should work, might be slow though...
hmm im asking because im fooling around at school making a sort of roguelike game, and I want it NOT to flicker as it redraws the characters. I had something like what elcrazon showed me, but it was too slow. Is system("cls") fast enough?
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
quote:Original post by Laroche
hmm im asking because im fooling around at school making a sort of roguelike game, and I want it NOT to flicker as it redraws the characters. I had something like what elcrazon showed me, but it was too slow. Is system("cls") fast enough?


Redraw only what needs to be redrawn, and write spaces to erase what needs to be erased. No cls.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"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
Im not quite sure how I could only redraw parts of the map? Its stored in a multi-dimensional array of CTiles, which basically just have a char representing the onscreen "sprite" and an int for the effect it has. Its all been wrapped into a CMap class with a function called "render", which basically looks like this:

  for (int y = 0; y < Height; ++y){for (int x = 0; x < Width; ++x){cout << pMap[x + y * Width].Sprite;}}  


How would I write a function like render which would only update changes or something? Im a little lost, since im used to using graphics and not chars (im doing it for fun to fool around a bit)
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
if you hack around, theres a way to get the DC and write to it (via blt). if i find the code, ill post it.
Look at the console functions (starting with those referenced in the MSDN article/code snippet), there are functions that let you change the position of the console cursor (i.e. choose where to write). It also has functions that will actually do the output.

At that level, I''m not sure how will streams interact with them.

you might also search for "ANSI control sequences", though it will not work on Win2k & later consoles (works fine in terminals like telnet, if you''re doing a networked version of nethack (finally ))

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"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

This topic is closed to new replies.

Advertisement