Public Group

How do I clear the screen in a console app (c++)

This topic is 4964 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Ok, I'm not writing a game but I figured this is the best place for a piece of advice. How do I simply clear the screen? I know there is a command. I just don't know it. :) Thank You.

Share on other sites
I think it's system("cls");

Share on other sites
THANKS A MILLION!!!! :D

Share on other sites
Or system("clear")

Share on other sites
i hate it how ther's no universal solution (cross platform) to this common problem.. or is there?

Share on other sites
Printing out lots and lots of spaces and/or newlines.

Unfortunatley I don't know of a command that works on both unix and windows.

Course you could always get the user to create an alias that alias one to the other, but yes this is a stupid idea.

Share on other sites
Quote:
 Original post by BoderOr system("clear")
Doesn't seem to work with Mingw/GCC.

#include <iostream>main(){        std::cout << "Hello World...\n\nPress Enter.";        std::cin.get();        std::system("cls");        std::cout << "Once Again, Hello World!\n\nPress Enter.";        std::cin.get();}

Share on other sites
Quote:
Original post by Rob Loach
Quote:
 Original post by BoderOr system("clear")
Doesn't seem to work with Mingw/GCC.

*** Source Snippet Removed ***

It is not up to the compiler, it is up to the system.
"clear" isn't a command in my windows too.

Share on other sites
The correct one is as Meta Adam said, its system("cls") as cls is the clear command for the windows command prompt (carried over from the old dos operating systems) clear is for linux systems.

Share on other sites
Quote:
 i hate it how ther's no universal solution (cross platform) to this common problem.. or is there?

Oh, but there is (assuming a terminal that supports VT100).

The escape sequence is ^[[2J. In C++, that's cout << "\33[2J". See VT100 escape codes.

1. 1
2. 2
3. 3
JoeJ
20
4. 4
5. 5
frob
19

• 11
• 11
• 12
• 13
• 9
• Forum Statistics

• Total Topics
632213
• Total Posts
3004849

×