异步从stdin读取Boost asio 我想从标准输入(C++,STD::CIN)中读取Boost ASIO函数AycCyRead()。下面的代码没有编译,由于实例化错误,给了我一条很长的错误消息。有人可以回答,我如何使用这个函数异步读取stdin char buf[64]; boost::asio::async_read(std::cin, boost::asio::buffer(buf), [](const boost::system::error_code &ec, std::size_t size){});
编辑:我知道这里已经提出了一个类似的问题,但是我不清楚标记的答案与问题的关系如何您必须使用异步从stdin读取Boost asio 我想从标准输入(C++,STD::CIN)中读取Boost ASIO函数AycCyRead()。下面的代码没有编译,由于实例化错误,给了我一条很长的错误消息。有人可以回答,我如何使用这个函数异步读取stdin char buf[64]; boost::asio::async_read(std::cin, boost::asio::buffer(buf), [](const boost::system::error_code &ec, std::size_t size){});,c++,boost,asio,C++,Boost,Asio,编辑:我知道这里已经提出了一个类似的问题,但是我不清楚标记的答案与问题的关系如何您必须使用posix::stream\u描述符 例如: using namespace boost::asio; io_context ioc; posix::stream_descriptor input_stream(ioc, STDIN_FILENO); // assume that you already defined your read_handler ... async_read(inp
posix::stream\u描述符
例如:
using namespace boost::asio;
io_context ioc;
posix::stream_descriptor input_stream(ioc, STDIN_FILENO);
// assume that you already defined your read_handler ...
async_read(input_stream, buffer(buf), read_handler);
ioc.run();
请注意,您不应将上述代码与std::cin
有关更多信息,请参阅。好的,这对我来说已经足够了,但出于好奇,是否有windows和posix兼容的解决方案?您好。您可以尝试将控制台输入绑定到
windows::object\u handle