Clear

K

KL

I was thinking...not always a good thing...is there a way to clear your
screen. Like my current program asks a question and then posts 6
possible answers to choose from. Once a valid answer is chosen, it
goes on to the next question, but it is hard to follow, so I was
wondering if I could clear the screen after the answer was given and
start with a fresh screen for each question.

KL
 
R

Rolf Magnus

KL said:
I was thinking...not always a good thing...is there a way to clear your
screen.

No portable one, since standard C++ doesn't even have a concept of a
"screen".
Like my current program asks a question and then posts 6
possible answers to choose from. Once a valid answer is chosen, it
goes on to the next question, but it is hard to follow, so I was
wondering if I could clear the screen after the answer was given and
start with a fresh screen for each question.

The only fairly portable way would be to write a bunch of newlines out so
the output window has to scroll the text up until none is left on screen.
Another way, if you have an ANSI terminal - or an emulation of one, is to
print a specific escape sequence.
There are also libraries to handle text screen output, like (n)curses. Those
libraries typically support clearing the screen.
 
S

Stephen Howe

I was thinking...not always a good thing...is there a way to clear your
screen.

I am sure there is a way to "clear the screen".
But not in standard C++.
"Clearing the screen" is OS-specific, so you need to ask how it is done in a
newsgroup devoted to programming for your OS.

Stephen Howe
 
K

KL

Stephen said:
I am sure there is a way to "clear the screen".
But not in standard C++.
"Clearing the screen" is OS-specific, so you need to ask how it is done in a
newsgroup devoted to programming for your OS.

Stephen Howe

Thank you all for your inputs. It isn't necessary for this assignment,
I just thought it would crisp it up a bit.

KL
 
J

just

KL said:
I was thinking...not always a good thing...is there a way to clear your
screen. Like my current program asks a question and then posts 6
possible answers to choose from. Once a valid answer is chosen, it
goes on to the next question, but it is hard to follow, so I was
wondering if I could clear the screen after the answer was given and
start with a fresh screen for each question.

KL

You need to find the screen size which is not standard
try this:

for(int i=0;i<size_of_screen;i++)
{
cout << endl;
}
 
B

ben

You need to find the screen size which is not standard
try this:

for(int i=0;i<size_of_screen;i++)
{
cout << endl;
}

This would be a nuissance if the output stream is redirected to a file or a
printer.

Ben
 
R

roberth+news

(e-mail address removed) wrote:
| try: system ("cls");

$ cat cls.cc
#include <cstdlib>

int main()
{
std::system("cls");
}

$ g++ -ansi -Wall -pedantic -o test cls.cc
$ ./test
sh: line 1: cls: command not found
$

As you can see, system("cls") will only work on systems with a command
named cls, and use of this method will tie your program to these
systems. As I recall, the OP wanted to make a more fancy UI for his
homework. I cannot recall him saying that both he and his project's
evaluator are using such a system. Only standard C++ will be guaranteed
to work. And: No, there is no way to clear the screen with standard C++
today.
 
A

abecedarian

Robert said:
As you can see, system("cls") will only work on systems
with a command named cls, and use of this method will
tie your program to these systems.

Of course. That's the point of 'system' :) Change "cls" to the
command appropriate for your _system_ and create incredibly tight ties
to that system.
 
R

Richard Herring

(e-mail address removed) wrote:
| try: system ("cls");

$ cat cls.cc
#include <cstdlib>

int main()
{
std::system("cls");
}

$ g++ -ansi -Wall -pedantic -o test cls.cc
$ ./test
sh: line 1: cls: command not found
$

As you can see, system("cls") will only work on systems with a command
named cls

Not even then, on many of them - it may well run the "cls" command in
its own virtual "screen", which won't help at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,666
Latest member
selsetu

Latest Threads

Top