C clear screen

Pages: 12
Oct 6, 2010 at 11:16pm
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?
Oct 7, 2010 at 12:11am
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/
Oct 7, 2010 at 12:12am
cross-platform... tricky. i would suggest making lots of spaces cout<<endl but that's just because im lazy.
Oct 7, 2010 at 1:07am
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.
Oct 7, 2010 at 4:57pm
if you're doing windows, use this: system ("cls")
Oct 7, 2010 at 5:01pm
@sargon94 : Don't use system("anything") , see http://www.cplusplus.com/forum/articles/11153/
Last edited on Oct 7, 2010 at 5:02pm
Oct 7, 2010 at 5:18pm
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;
}
Oct 7, 2010 at 5:32pm
@ Null: why not! if he's using windows (which i stated as a prerequisite, see above), system ("most things") works fine!
Oct 7, 2010 at 6:11pm
why not!


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

http://www.cplusplus.com/forum/articles/11153/
Oct 7, 2010 at 6:38pm
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
Oct 7, 2010 at 6:53pm
lololololol....

Thats all I got to say.
Oct 7, 2010 at 8:23pm
@wtf: laugh all you want, but the same goes for you...
Oct 7, 2010 at 8:28pm
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
Oct 7, 2010 at 8:31pm
@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
Oct 7, 2010 at 8:35pm
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...
Oct 7, 2010 at 8:39pm
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.
Oct 7, 2010 at 8:43pm
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.
Oct 7, 2010 at 8:43pm
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.
Oct 7, 2010 at 9:22pm
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.
Oct 7, 2010 at 9:25pm
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