Copy a streambuf's contents to a string

前端 未结 10 2011
时光取名叫无心
时光取名叫无心 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

    It's really buried in the docs...

    Given boost::asio::streambuf b, with size_t buf_size ...

    boost::asio::streambuf::const_buffers_type bufs = b.data();
    std::string str(boost::asio::buffers_begin(bufs),
                    boost::asio::buffers_begin(bufs) + buf_size);
    

提交回复
热议问题