我的问题是,如何让数字 10 - 0 在同一行打印出来,使用 WIN32 或 GNUC 编译器以简单的方式相互覆盖,如下面的代码:
这是我到目前为止所拥有的:
#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