Visual Studio ok to use system("CLS")

After searching and reading a bit about Visual Studio clearing the screen. People generally say system("CLS") is the way to go, but it is said that using system is bad. Is it ok to use in Visual Studio? If not would it be fine if I just use system("CLS") once in my code?
this is fine.
The problem with system is that it is external to your code, so some bunghole can install cls.exe in the same folder as your program where cls.exe is a virus, and that would run the virus program instead of the standard console clear screen command. Honestly, if they can do that, they already own your system anyway. ALL uses of system can be compromised with simple methods like this. That is why it is "bad".

This is highly unlikely to happen if you are just learning some code and working on your own machine. If you plan to sell and distribute your program, you should do something else (there are more secure versions of system, but they take a bunch of parameters and have complexity that isnt worth getting into right now.).

Last edited on
At the risk of beating a dead horse:
The std::system function is not bad.

However:
Clearing the screen of a console application is usually bad practice. And calling std::system("CLS") is an awfully slow and roundabout way to run arbitrary code that might or might not actually clear the screen.

If you know that clearing the user's console is acceptable, and you understand that a call to std::system is very slow and may or may not do what you intend, feel free to use it.

There are plenty of real-world examples where calling the system's shell is perfectly acceptable. This particular case usually isn't a good one.

Edit: Sorry to repeat you @jonnin
I hadn't refreshed the page.
Last edited on
Registered users can post here. Sign in or register to post.