What is a simple alternative to the system ("CLS")?
There are two ways:
Function creation:
void ClearScreen()
{
int n;
for (n = 0; n < 10; n++)
printf( "\n\n\n\n\n\n\n\n\n\n" );
}
This just creates a function that displays 100 new lines. Slow, pathetic, but it works.
Also the only other OS-dependent way not to use system("cls")
will work with ncurses and PDCurses , although they might be overkill for small projects.
NCurses works for Unix and Linux and other POSIX systems, while PDCurses works for DOS, Windows, OS / 2 and some other random systems.
source to share
I don't have one for the system ("CLS"). But you can use the Sleep (int) function. It is not configured as a system ("PAUSE"), but you can configure the rest. The function pauses the program for as long as you like. Its parameter is an integer and according to its value the program sleeps. It is millisecond based. so Sleep (1000) pauses the program for 1000 milliseconds, or 1 second, because 1000ms = 1s.
#include "iostream" // for the cout
#include "windows.h" // for the Sleep() function
using namespace std;
int main(){
cout << "hello" << endl;
Sleep(6000); // pauses program or puts it to 'sleep' for 6000 ms or 6 s
return 0;
}
source to share