+ 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.

31st Jan 2017, 1:36 AM
Ipshita Ghosh
Ipshita Ghosh - avatar
4 odpowiedzi
+ 9
If your platform is Windows, the solution N3tW0rK provided is impeccable. :>
31st Jan 2017, 2:40 AM
Hatsy Rei
Hatsy Rei - avatar
+ 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; }
31st Jan 2017, 2:17 AM
Kawaii
Kawaii - avatar
+ 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; }
31st Jan 2017, 2:59 AM
Megatron
Megatron - avatar
0
my compiler was not supporting windows.h header file. I am using windows 32 bit, should I use dosbox compiler?
31st Jan 2017, 4:01 AM
Ipshita Ghosh
Ipshita Ghosh - avatar