How do I clear screen?

I understand that in CMD console, The Cls command would basically clear the screen. And since all the program I am currently writting is run with the window CMD console. How would I make it so that my program can clear the screen? I tried something like system.cls(); system.clear(); hehe. None of the work.

Last edited on
Thx mike. Wow, It's like a whole new world just open up to me. I can do so much more now that I know how to manipulate the CMD console using c++. hehe. Beautiful.

I highly recommend you don't stick to this method.
You can simply do:
cout << string(50, '\n');

to print lines to seem like the terminal was 'cleared'.

The reason is that the system() function calls system-specific functions, which makes your program less portable.

I'm too tired to explain, so I hope Duoas will come and help with the downsides of the system() function.

But trust me, don't use it.

I had to learn from experience.
On Windows:

system() is evil. Use it at your own peril (aka job security). I've said it often enough. Most simply it is resource heavy and a security hole.

But probably most importantly, you shouldn't be dinking with the screen in stream applications. It is a UI faux-pas.

It seems really popular in homework though...
Last edited on
what header files do i need to include so that i can use system()?
Yep. I got you guys. It's bad practice, not system portable, and technically not C++ specific.

But for now I am just programming in CMD console. I just need to manipulate the screen a little...hehehe. And it make my menu look good. lolz.

Tinman, if I am correct you wouldn't need any header files. If you are writting your program to run in console, then it simply uses the command available to you on your CMD console. And there are a lot of them, but like Duoas, and PersonJerry pointed out, that is highly bad practice.

He's talking about what to #include so that he can use the system() function.
#include <cstdlib>
You can find out what header to include by going to the homepage and typing the name of the function into the search box, selecting it from the top of the page you see next, and looking to the right to see what the header file is.

I've got no problem with using system("PAUSE") as long as people don't start thinking it is good for production code.
Topic archived. No new replies allowed.