私の質問は、以下のコードのような簡単な方法でWIN32またはGNUCコンパイラを使用して互いに上書きし、同じ行に10-0の数字を出力するにはどうすればよいですか。
これは私がこれまでに持っているものです:
#include <iomanip>
#include <iostream>
using namespace std;
#ifdef __GNUC__
#include <unistd.h>
#elif defined _WIN32
#include <cstdlib>
#endif
int main()
{
cout << "CTRL=C to exit...\n";
for (int units = 10; units > 0; units--)
{
cout << units << '\r';
cout.flush();
#ifdef __GNUC__
sleep(1); //one second
#elif defined _WIN32
_sleep(1000); //one thousand milliseconds
#endif
//cout << "\r";// CR
}
return 0;
} //main
しかし、これは印刷するだけです:
10 9 8 7 6 5 4 3 2 1