Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently clearing my console window with this piece of code:

void clrScr()
    COORD cMap =
        0, 3
    if(!FillConsoleOutputAttribute(hCon, 0, 2030, cMap, &count))
        std::cout << "Error clearing the console screen." << std::endl;
        std::cout << "Error code: " << GetLastError() << std::endl;

, which I call once in the main loop.
But since my window is quite large (70x35), it's flickering quite a bit.

I was wondering if there are any faster methods of doing this?

share|improve this question
Have a look at ncurses for a platform neutral techniques for clearing a console window. – Loki Astari Dec 4 '12 at 7:33
Not really looking for a new lib. Thanks anyways. – user19953 Dec 4 '12 at 9:57
You should be looking for a new lib. You are using standard IO for stuff which it wasn't meant to be used for. – Winston Ewert Dec 5 '12 at 21:27

Have a look at Clear the Screen. It basically boils down to using what you did (since the Windows console doesn't accept standard ansi sequences), although you might try the conio.h route.

share|improve this answer
I can't use clrscr() for some reason. Probably something to do with the fact that it's non-standard. And pretty much the only other way (without using external libs) would be the way I'm doing it.. It seems there are no better ways of doing this, so I won't accept an answer, at least for now. If there are no better answers after a while, I'll accept yours. – user19953 Dec 5 '12 at 23:09

How about


This clears the entire console nicely

share|improve this answer
That is actually WAY slower than my method. Also, system calls are supposedly very bad coding practice. – user19953 Dec 4 '12 at 2:21
up vote 0 down vote accepted

I decided that the best way to clear the screen - at least for a text-based game in console - is to clear literally only the individual squares that need to be cleared, instead of the whole window.

share|improve this answer
Which is indeed almost the right and proper way to handle it in a game - if only you'd told us that :) But you could try overprinting with the new contents rather than clearing first. – Glenn Rogers Dec 6 '12 at 7:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.