After reading why system()
is evil, I decided to not use features like system("CLS")
and system("PAUSE")
. Are there any easy alternatives that aren't OS dependent?
There are two ways:
Creating a function:
void ClearScreen()
{
int n;
for (n = 0; n < 10; n++)
printf( "\n\n\n\n\n\n\n\n\n\n" );
}
This simply creates a function that displays 100 new lines. Slow, pathetic, but it works.
Also the only other non-OS dependent way to not use system("cls")
would be working with ncurses and PDCurses, although they can be overkill for smaller projects.
NCurses works for Unix and Linux and other POSIX systems, and PDCurses works for DOS, Windows, OS/2, and some other random systems.
As mentioned before, there is no portable way of "clearing" the screen. There however a portable way of "emulating" Windows' system("pause")
, namely
std::cin.get(); // waits for ENTER
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With