1

I have read a few articles online about clearing the console with c++ in windows by using system("cls");

A few people told me using system commands isn't practical and it may be unsafe.

I would like to know why, seeing as i'm building a little console program for uni that has a menu at the start.

Is it perfectly safe and professional to use system("cls"); at home and in the workforce?

victor gatto
  • 61
  • 1
  • 3
  • Anything using system is inherently non portable. May not matter depending on the context. – John3136 May 02 '13 at 07:17
  • I recommend you look through the available [console function](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.100%29.aspx), I'm sure you'll find something usefull there. – Some programmer dude May 02 '13 at 07:17
  • By saying non-portable, you mean non cross-platform right? – victor gatto May 02 '13 at 07:22
  • I think it depends on what the application is for and what you mean by 'safe'. I know you said you're using Windows, but as an example, if you wanted a console app on Linux / OSX to clear the screen because you want to hide the data, calling the Linux 'clear' command doesn't stop the user scrolling up the screen to see what was previously displayed. I can't remember if Windows is the same. Anyhow, Perhaps those that said it was unsafe were referring to something like that. – TheDarkKnight May 02 '13 at 08:00
  • Maybe you want to have a look at this: http://stackoverflow.com/questions/6486289/how-can-i-clear-console – TobiMcNamobi May 02 '13 at 08:03
  • ... and this: http://support.microsoft.com/kb/99261/EN-US – TobiMcNamobi May 02 '13 at 08:05

1 Answers1

1

Please note: The command "cls" is windows specific. The counterpart on Linux systems is command "clear". Hence system("cls") is not portable.

Prefer curses library as it is cross-platform. Want to quick (hacky?) way, look at clear the screen!

Also, have a look at How do you clear console screen in C?

Community
  • 1
  • 1
Arun
  • 2,087
  • 2
  • 20
  • 33