I made a really trivial modification (basically, just clear it and make it more readable):
#include <iomanip> #include <iostream> using namespace std; #ifdef __GNUC__ #include <unistd.h> #define pause(n) sleep(n) #elif defined _WIN32 #include <cstdlib> #define pause(n) _sleep((n)*1000) #endif int main() { cout << "CTRL=C to exit...\n"; for (int units = 10; units > -1; units--) { cout << setw(2) << setprecision(2) << units << '\r'; cout.flush(); pause(1); } return 0; }
This worked great with both VC ++ and Cygwin. If it does not work under control, it sounds to me like an implementation problem.
source share