Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
异步从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 - Fatal编程技术网

异步从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