#include <future>
#include <iostream>
#include <string>
#include <thread>
std::string GetLineAsync()
{
std::string input;
std::getline(std::cin, input);
return input;
}
int main()
{
auto future = std::async(std::launch::async, GetLineAsync); // future is of type 'std::future<std::string>'
while (future.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
std::cout << "Waiting for input (doing something else in the meanwhile)..." << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(1)); // This thread job
}
// Input is ready:
const std::string input_c = future.get();
std::cout << "Input: " << input_c << std::endl;
}