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

Started by
11 comments, last by Anon Mike 19 years, 3 months ago
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.
Advertisement
I think it's system("cls");
Meta AdamOne of a million noob C++ programmers.
THANKS A MILLION!!!! :D
Or system("clear")
i hate it how ther's no universal solution (cross platform) to this common problem.. or is there?
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.
Quote:Original post by Boder
Or 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();}
Rob Loach [Website] [Projects] [Contact]
Quote:Original post by Rob Loach
Quote:Original post by Boder
Or 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.
pex.
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.
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.
Free Mac Mini (I know, I'm a tool)

This topic is closed to new replies.

Advertisement