Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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;
        std::cin.get();
    }
}

, 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
2  
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
2  
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
add comment

3 Answers

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
add comment

How about

system("cls");

This clears the entire console nicely

share|improve this answer
4  
That is actually WAY slower than my method. Also, system calls are supposedly very bad coding practice. –  user19953 Dec 4 '12 at 2:21
add comment
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
add comment

Your Answer

 
discard

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