Copy a streambuf's contents to a string

前端 未结 10 2029
时光取名叫无心
时光取名叫无心 2020-11-29 22:19

Apparently boost::asio::async_read doesn\'t like strings, as the only overload of boost::asio::buffer allows me to create const_buffer

10条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 23:13

    A simpler answer would be to convert it in std::string and manipulate it some what like this

     std::string buffer_to_string(const boost::asio::streambuf &buffer)
     {
      using boost::asio::buffers_begin;
      auto bufs = buffer.data();
      std::string result(buffers_begin(bufs), buffers_begin(bufs) + buffer.size());
     return result;
    }
    

    Giving a very concise code for the task.

提交回复
热议问题