mercredi 28 mars 2018

Why doesn't std::this_thread::sleep_for() work in MacOS terminal?

Explanation

Take for example this basic code.

#include <iostream>
#include <thread>

int main(int argc, const char * argv[]) {
    while(true){
        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
        std::cout << "loop";
    }
}

When I run this in XCode, it works exactly as expected. Every second it prints out, "loop". However, when I run this in my terminal, nothing happens. The code seems to be "running" but nothing gets printed to screen.

Question:

Why does std::this_thread::sleep_for() work in the XCode terminal but not the standard MacOS terminal?

Aucun commentaire:

Enregistrer un commentaire