Jump to content
  • Advertisement
Sign in to follow this  
JTekNet

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
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();
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!