簡體   English   中英

boost::asio::read_until 不接受套接字作為參數

[英]boost::asio::read_until does not accept a socket as an argument

讀過您可以使用boost::asio::read_until從套接字讀取,所以我嘗試這樣做:

using namespace boost::asio;
  ...
    boost::array<char, BUFFER_SIZE> buf;
    read_until(this->socket_opt.value(), buffer(buf), "\n");

但顯然,read_until 不能接受那些 arguments:

error: no matching function for call to ‘read_until(const boost::asio::basic_stream_socket<boost::asio::ip::tcp>&, boost::asio::mutable_buffers_1, const char [2])’
        read_until(this->socket_opt.value(), buffer(buf), "\n");

我究竟做錯了什么?

PS socket_opt 被定義為std::optional<boost::asio::ip::tcp::socket> socket_opt並且在運行時有一個值。

boost::asio::read_until()需要動態緩沖區作為第二個參數。

希望下面的代碼對你有所幫助。

boost::asio::streambuf buf;
boost::asio::read_until(this->socket_opt.value(), buf, "\n");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM