Copy a streambuf's contents to a string

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

    One can also obtain the characters from asio::streambuf using std::basic_streambuf::sgetn:

    asio::streambuf in;
    // ...
    char cbuf[in.size()+1]; int rc = in.sgetn (cbuf, sizeof cbuf); cbuf[rc] = 0;
    std::string str (cbuf, rc);
    

提交回复
热议问题