system("CLS");

Better options?

Page 1 of 1

11 Replies - 8590 Views - Last Post: 13 May 2010 - 03:53 PM Rate Topic: -----

#1 alias120  Icon User is offline

  • The Sum over All Paths
  • member icon

Reputation: 122
  • View blog
  • Posts: 700
  • Joined: 02-March 09

system("CLS");

Posted 06 May 2010 - 07:18 PM

I have been looking for a way to clear the console screen, and the only method I have found is to use

system("CLS");



Does anyone know of a function in the STL that can be called to accomplish this?


-alias
Is This A Good Question/Topic? 0
  • +

Replies To: system("CLS");

#2 Guest_Oler1s*


Reputation:

Re: system("CLS");

Posted 06 May 2010 - 07:26 PM

Clearing the screen is not part of the SC++L. That's because such functionality is OS specific.
Was This Post Helpful? 0

#3 IngeniousHax  Icon User is offline

  • |>|20-514<|{3|2

Reputation: 78
  • View blog
  • Posts: 1,358
  • Joined: 28-March 09

Re: system("CLS");

Posted 06 May 2010 - 07:26 PM

IDK of a function, but you could always write a bunch of newlines to the screen....

for(int i = 0; i < 80; i++)
    cout << "\n";


Was This Post Helpful? 0
  • +
  • -

#4 alias120  Icon User is offline

  • The Sum over All Paths
  • member icon

Reputation: 122
  • View blog
  • Posts: 700
  • Joined: 02-March 09

Re: system("CLS");

Posted 06 May 2010 - 07:31 PM

View PostOler1s, on 06 May 2010 - 06:26 PM, said:

Clearing the screen is not part of the SC++L. That's because such functionality is OS specific.


Good call, I don't know why I didn't realize that. I suppose I will have to stick with making calls to the system.
Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: system("CLS");

Posted 06 May 2010 - 07:45 PM

If you're on Windows, gabehabe has a snippet for it.
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: system("CLS");

Posted 06 May 2010 - 07:46 PM

If he were not on Windows, he wouldn't be using CLS successfully :)
Was This Post Helpful? 0
  • +
  • -

#7 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3105
  • View blog
  • Posts: 19,144
  • Joined: 14-September 07

Re: system("CLS");

Posted 06 May 2010 - 08:04 PM

I'm a tard.
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: system("CLS");

Posted 06 May 2010 - 08:05 PM

Thus explaining the bicycle helmet with the sticker that reads "I love puppies".
Was This Post Helpful? 0
  • +
  • -

#9 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1075
  • View blog
  • Posts: 4,536
  • Joined: 09-June 09

Re: system("CLS");

Posted 06 May 2010 - 08:06 PM

you could just use the preprocessor to help find what clear command you need
#ifdef WIN32 //if on windows
#define clear system("cls")
#else LINUX
#define clear system("clear")
#endif


Was This Post Helpful? 0
  • +
  • -

#10 alias120  Icon User is offline

  • The Sum over All Paths
  • member icon

Reputation: 122
  • View blog
  • Posts: 700
  • Joined: 02-March 09

Re: system("CLS");

Posted 06 May 2010 - 09:47 PM

View PostKYA, on 06 May 2010 - 06:45 PM, said:

If you're on Windows, gabehabe has a snippet for it.


Would
 system("CLS") 
have more overhead than writing that function? I see that they are both Windows specific, i've always been under the impression that making specific calls the to system should be avoided if possible, as if it resource intensive. Which would make using your own function the logical choice.
Was This Post Helpful? 0
  • +
  • -

#11 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: system("CLS");

Posted 06 May 2010 - 09:54 PM

Quote

have more overhead than writing that function?
Yes.

Quote

I see that they are both Windows specific, i've always been under the impression that making specific calls the to system should be avoided if possible, as if it resource intensive.
Resource intensive, and I believe I can construct a situation where you get unexpected behavior (feasible, but an advanced situation).
Was This Post Helpful? 0
  • +
  • -

#12 Guest_JdeBP*


Reputation:

Re: system("CLS");

Posted 13 May 2010 - 03:53 PM

View Postalias120, on 06 May 2010 - 06:18 PM, said:

system("CLS");



Others have erroneously deduced from this that you are using Windows. You may not be. The above bad idea is used by DOS programmers and OS/2 programmers, too, both of which have CLS commands in their command interpreters.

You've been pointed to a Win32 snippet. Note that the snippet doesn't give you a scrollback region in your console. For code that does, see the Frequently Given Answer on how one goes about clearing the screen in a TUI program, in particular the Win32 section. There are even two different approaches provided, one of which allows you to duplicate the scrollback behaviour of 4NT's/TCC's CLS command, which, for all we know, could be the CLS command that you are invoking. (-:

The Frequently Given Answer also explains why
system("clear");


as also mentioned here is similarly a bad idea on Linux, and how one clears the screen properly on programs for POSIX systems.
Was This Post Helpful? 0

Page 1 of 1