I tested some C ++ 11 code, and I tried to write a program that counts from 10, sleep between pins. Here is what I still have:
#include <iostream>
using namespace std;
#include <chrono>
#include <thread>
void Sleep(int x)
{
std::this_thread::sleep_for(std::chrono::duration<int>(x));
}
int main()
{
for (int x=10; x>0; x--) {
cout << x << "...";
Sleep(1);
}
cout << " FIRE!!\n";
}
The problem is that this code waits 10 seconds and then prints all the output, rather than counting from 10. How does this happen? And how can I fix this?
(By the way, I tried this on a computer running Linux Mint 17 and MacOSX 10.9, and both times I got the same result)
source
share