Clear output ?

+1 Cardinal Coog · January 7, 2015
I would like to know how to clear the terminal screen while the program is running.

Everyone I've asked always says, something to the effect of:

cout << string(50, '\n');

All that really does is move the cursor 50 lines down. I want the terminal screen to clear out and then display new output.

Thanks for any help you can give.

Post a Reply

Replies

Oldest  Newest  Rating
0 Bernard Pyc0d333 Parah · January 7, 2015
thought I answered already :)

use the cstdlib header

on windows use
system("cls"):

on linux, use clear instead of cls in the parentheses
0 Gaston Seneza · January 7, 2015
cls will clear it. it is also worth noting that cls will clear all commands that you may write in CMD (Command prompt on windows. try running some window commands, for example try opening command promtpt on the screen and type                    in tree, and you will see a long commands. then type in cls, it will all be cleared. cls is a very powerful command.
0 Bernard Pyc0d333 Parah · January 7, 2015
nope ..the command is platform dependent. The clear command is used to clear terminals while cls is used on the windows dos shell.

sp when you use the commands interchangeably, you will get error messages.
To answer you, there is no such command that is crossplatform that I know of, as long as it is c++ and its a console application.
0 Cardinal Coog · January 7, 2015
Thanks... You're right. I'm not thinking logically today.:'(
0 Bernard Pyc0d333 Parah · January 7, 2015
Haha....too much coding I guess :).
was a helpful question though
+1 c student · January 7, 2015
doesn't matter if it's cross platform or not, c++ is not platform independent and will never run on unix if compiled for a windows machine and vice versa (unless you use wine, of course)
0 Bernard Pyc0d333 Parah · January 7, 2015
yea c student...good point
  • 1

C++

107,200 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator