Since starting c++ programming 4 months ago in my highschool class, When I learned system commands, I thought "wow these are helpful, (for ex, system("cls"), system("pause"), system(color ##") although color I do agree we can do without) why are these frowned upon? I use them all the time because I know no alternative, except for color :D. Can people list some alternatives for these
system("cls")
system("pause")
and reading through the forums, I saw someone said the alternative for cls is not using it, but why wouldn't I want to clear the screen? Because I dont want all of my output to cludder in larger program(A console game I'm creating for school for example).
The main reason not to use it is that it is not portable. The system() command adds external dependencies. You cannot take that program that does "cls" on Windows and then run it on Mac or Linux.
But then what do professional programmers, well if they even do console based programs, use instead of cls? is there a c++ based screen clearing command?
They do not clear the screen. Very few console program shipped with windows or Unix do this. Look at "dir" (or "ls" on Unix) for example. If the user wants the screen cleared, they can write a batch or shell script that does it for them.
Most of these things are things console programs shouldn't do because it interferes with other console programs.
Console programs are often run in batches, so that when one program finishes, another one starts -- allowing you to complete a somewhat complex task quickly and without interruption.
The problem with these things is that they break that smooth chain.
"pause" prompts the user for input. This is bad in a console environment because it breaks the automation of batch program running. If every program paused, you'd have to pointlessly hit enter a dozen times whenever you ran a batch file.
"cls" clears the screen. This is bad in a console environment because it erases the output of all programs that ran previously, not allowing the user to see the result of those programs.
well, and I know the obligatory article will be posted. Should you be writing a console based game a clear function may be in order. Now whether or not this is relevant due to its quality of choice, I'll leave up to anyone else.
My program, outputs alot of information that becomes irrelevant to current input in the program, usually I group pause and cls together." so user inputs, switch chooses output, couts input, pauses, clears the screen, and restarts with new information(making the original input, output, unnecessary to still have displayed"
I do understand now why its frowned upon though, but in a program, should I create a void function once at the top using system("cls"); and just call the function whenever i'd like to clear the screen?(instead of putting cls ever 10 lines or so.) and from now on instead of pause use that cin.get?
Don't use system at all, if you need to clear the screen search the API for the operating system you are developing for, for the appropriate system calls.
Alright, I'm just planning on not clearing the screen anymore, i'll use someone else methods of skipping a large amount of lines so the screen appears to be cleared cout << string(50, '\n'); Thanks "PersonJerry"
for now I'm not using any graphics API so this'll do