我想用boost asio函数async_read()读取标准输入(就c++而言,std::cin)。由于实例化错误,以下代码无法编译,并给出了一条非常长的错误消息。有没有人能回答,我如何使用这个函数异步读取标准输入?
char buf[64];
boost::asio::async_read(std::cin, boost::asio::buffer(buf),
[](const boost::system::error_code &ec, std::size_t size){});编辑:我知道这里已经有一个类似的问题,Using boost::asio::async_read with stdin?,但我不清楚标记的答案与问题的关系
发布于 2019-11-10 05:59:54
您必须使用posix::stream_descriptor
例如:
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混合使用
有关详细信息,请参阅here。
https://stackoverflow.com/questions/58783797
复制相似问题