Copy a streambuf's contents to a string

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

    I tested the first answer and got a compiler error when compiling using "g++ -std=c++11" What worked for me was:

            #include 
            #include 
            #include            
            //other code ...
            boost::asio::streambuf response;
            //more code
            std::ostringstream sline;
            sline << &response; //need '&' or you a compiler error
            std::string line = sline.str(); 
    

    This compiled and ran.

提交回复
热议问题