Ok I know your not supposed to use it. Ive seen people say not to use it many times. I was just wandering why not use the system(). I havent actualyl seen anyone say why its bad to use.
Ok I know your not supposed to use it. Ive seen people say not to use it many times. I was just wandering why not use the system(). I havent actualyl seen anyone say why its bad to use.
Code:/* ------------------------------------------------------------------*/ // INSERT CODE HERE /* ------------------------------------------------------------------*/
security holes, non-portability...
every time you put system("cls") in your program, my computer doens't clear the screen... what it does is print a newline followed by "bash: cls: command not found" followed by another newline, then your program keeps on going.
on the other hand, what happens if I somehow get into your computer and remove cls.exe and replace it with my own program called cls.exe, that does a little more than clear the screen.
now when you run your program on your own machine, to you everything looks just peachy, but you could have just launced the most dangerous virus written on the planet
you're also spawning off another program to do your dirty work, and you don't have much control over the process once you do so.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
what major_small is true -- for programs you intend to give to someone else. But I have no whelms about using it for quick-and-dirty programs I write and don't want to bother implementing all that code in my program (it is not a trivel thing to do).
If someone has replaced cmd.com on my computer then I have much bigger problems than to worry about what system("cls") might do.
Oh ok...that sounds pretty bad. Ill have to stay away from that.
Code:/* ------------------------------------------------------------------*/ // INSERT CODE HERE /* ------------------------------------------------------------------*/
yeah, i gotta agree here - although I stress not using it, I use it for my own programs, although not to pause, and rarely to clear the screen... but for programs other people will see or use I dont' use it.Originally Posted by Ancient Dragon
think of it as cutting corners and throwing caution to the wind.
one way you can make yourself feel better about it is by using wrapper functions - write something like this into your code:now you use clearScreen(); wherever you'd need to clear the screen, and you can always change the code in there whenever you move it to another system.Code:void clearScreen(){system("clear");}
Last edited by major_small; 03-30-2006 at 10:45 PM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
In case anyone does not know, AdrianXW has a tutorial on one method of clearing the screen without using the system. Me personally I use system("cls") all the time but I never thought about the portability issue. I may have to change how I do a few things.
Check oiut Adrian's web sit here
Using DEV-C++ Under Windows XP
+------------------------------+
"No! Do, or Do Not. There is no Try..."
adrian's site is all nice and good, but it's still not portable
he's focusing on windows programming, so he's using ostensibly safe methods to do those things in windows. Bottom line: there is no standard portable way to clear the screen - you have to make a compromise somewhere.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Like I said, he shows one way to do it.
When all else fails, you can always do a bunch of cout<<endl's untill everything goes off the screen. Its a bit ugly, but it will work
Using DEV-C++ Under Windows XP
+------------------------------+
"No! Do, or Do Not. There is no Try..."
it'd be better to ouput a whole bunch of newlines followed by an endl - flushing the buffer every time is slow.Originally Posted by rwmarsh
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
Well I found a way, not to clear the screen, but at least to pause it.
Works good enough for me. I counted so many lines, then placed cin.get() there. I have it set up to where like 19 lines are shown on screen. With a few "\n" after it so it takes up more lines but nothing is there. Then when enter is pressed, it appears as if the screen is being cleared and more text appears. Works fine for me.Code:int main() { cout << " line.\n"; cout << " line.\n"; cout << " line.\n"; cout << " line.\n"; cout << " line.\n"; cin.get(); // Shows first 5 lines. When user is ready they just press enter to continue. cout << " line.\n"; cout << " line.\n"; cout << " line.\n"; cout << " line.\n"; cout << " line.\n"; }
Code:/* ------------------------------------------------------------------*/ // INSERT CODE HERE /* ------------------------------------------------------------------*/
"portability" is only important when you write programs you know will be targed for more than one operating system. If you are writing MS-Windows programs with win32 api function calls, "portability" has been tossed to the wind anyway so you might as well use system("cls"). Or if you are writing a *nix program with *nix-specific functions then use system("clear"). And the security concern about what would happen if someone changed cmd.com is also a non-issue -- if someone did that then the os has a much larger problem then my using system() function because a lot of other programs will probably break too.
New students should not even be concerned about such issues -- tough enough to learn the language.
but it's tougher to learn it wrong and then have to relearn it laterOriginally Posted by Ancient Dragon
don't use system. it spawns a process you have no control over.
If you're writing windows code, use a windows API to do what you need to do. There's ALWAYS a better alternative to system().
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT
When you get to writing useful programs which run as
prog1 > results
or
prog1 | prog2
The whole 'cls' thing becomes an annoyance you can easily live without.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.