C clear screen

Pages: 12
Hello,

I'm trying to find a simple, cross platform way to clear the DOS screen. It doesn't really have to be fancy. I'm doing something for fun that a TA at my college said he'd give us candy for. The issue is, I'm writing the code using Dev-Cpp on Windows and he's reading and compiling the code on a Mac.

This is an entry level class and, as this is not an official project, just something for fun, the overall quality of how I get the clearing done doesn't matter. The project is supposed to test our switch-case statement knowledge, so the only thing this is really for is to make my project look a little nicer.

Anyone got anything?
Console != DOS. You are not doing anything relating to DOS, I can assure you.

Also, there is no easy way that is also crossplatform, unless you use a library.

See this: http://www.cplusplus.com/forum/articles/10515/
cross-platform... tricky. i would suggest making lots of spaces cout<<endl but that's just because im lazy.
Ok, console is what I mean.

Printing a bunch of new lines seems like the best thing for my case. Since this isn't anything big scale, or even graded, putting a whole lot of effort into clearing the screen wouldn't really do much good.

But looking at that thread, I could probably use some of that in platform specific projects that spring up later.
if you're doing windows, use this: system ("cls")
@sargon94 : Don't use system("anything") , see http://www.cplusplus.com/forum/articles/11153/
Last edited on
heck since you are supposed to be doing cross platform and using switches

just do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
char v;
#ifdef windows //I forget what the actual preprocessor directive is
v = 'w';
#endif

#ifdef unix //likewise I don't even know if this is valid, but something similar to this probably is
v = 'u';
#endif

switch(v)
{
     case 'w':
                   system("cls");
                   break;
     case 'u': whatevercommandisusedtocleartheunixconsole(); break;
     default: cout << "Please use an operating system then restart.\n" << endl; exit(99); break;
}
@ Null: why not! if he's using windows (which i stated as a prerequisite, see above), system ("most things") works fine!
why not!


Did you read that link Null gave you? It gives many, many reasons why not.

http://www.cplusplus.com/forum/articles/11153/
ok, i get it... now without using system ("cls") or cout<<endl clear the screen in windows in 1-4 lines. then tell me system sucks
lololololol....

Thats all I got to say.
@wtf: laugh all you want, but the same goes for you...
It would be funny if he ran the virus I called "cls" in the same directory as his program.

LOC doesn't mean anything. You can put the entire function on one line if you want to :P
@firedraco: 1. no one likes "how you word things techinally" Nazis... that being said, nice one, touche ;) and 2. i meant in 4 "commands" ended by semicolons
there, is that better?
oh and same goes for you as well
sargon94 wrote:
ok, i get it... now without using system ("cls") or cout<<endl clear the screen in windows in 1-4 lines. then tell me system sucks


Okay...

std::cout << string(100, '\n');

Now that I've done that, system("anything") sucks...
even if somehow you were to install a virus 'cls' on his computer, saying that system(" ") is insecure is a mute point because had you had access to his computer in the first place you could have gone ahead and ran the virus and not have to wait for someone to write a program that incorporated the use of system("cls"); to launch it.
Actually, getting someone to download a program is quite easy...getting them to run it is the hard part.

Go ahead and use system(), I just wouldn't want to work with you since it makes you seem like you are the same kind of guy of just puts everything in main because they understand it at the time.
system(" "); is insecure. What if you give the code to someone else, and they have the virus but it hasn't been activated? There are a lot of variables, but something that can be easily manipulated such as system(" "); should be avoided unless you're just messing around with the little stuff at home.
it makes you seem like you are the same kind of guy of just puts everything in main because they understand it at the time.


Actually I'm not like that. I highly functionalize. Maybe not as much as some, but i'm more the type to not bother commenting because I understand it at the time.
Look, all im saying is: if you're making a console program, might as well use cls. if you're making a WinAPI program all you so is SetItemText ("") and that will solve your problem
Pages: 12