+ 1
I want that, after printing a statement, the screen gets cleared after sometime, say 30 seconds. What command should I use?
It would be better if a timer is also visible. So that the user can know, when the screen is going to get cleared.
4 Respuestas
+ 9
If your platform is Windows, the solution N3tW0rK provided is impeccable. :>
+ 5
#include <iostream>
#include <cstdlib>
#include <windows.h>
int main() {
for (int i = 0; i < 4; i++) {
std::cout << "Hey" << std::endl;
}
Sleep(30000); // 30 sec
system("cls"); // clear the console
system("pause");
return 0;
}
+ 5
This one is OS independent version for delay/sleep function.
#include <iostream>
#include <ctime>
bool Wait(const unsigned long &Time)
{
clock_t Tick=clock_t(float(clock())/float(CLOCKS_PER_SEC)*1000.f);
if(Tick<0)
{
return 0;
}
clock_t Now=clock_t(float(clock())/float(CLOCKS_PER_SEC)*1000.f);
if(Now<0)
{
return 0;
}
while((Now - Tick)<Time)
{
Now=clock_t(float(clock())/float(CLOCKS_PER_SEC)*1000.f);
if(Now<0)
return 0;
}
return 1;
}
using namespace std;
int main() {
if(Wait(100))
cout<<"done";
return 0;
}
0
my compiler was not supporting windows.h header file. I am using windows 32 bit, should I use dosbox compiler?