How to asynchronously read to std::string using Boost::asio?

前端 未结 4 1657
野性不改
野性不改 2020-12-08 11:55

I\'m learning Boost::asio and all that async stuff. How can I asynchronously read to variable user_ of type std::string? Boost::asio::buffer(user_)

4条回答
  •  囚心锁ツ
    2020-12-08 12:10

    This isn't intended to be an answer per se, but just a lengthy comment: a very simple way to convert from an ASIO buffer to a string is to stream from it:

    asio::streambuf buff;
    asio::read_until(source, buff, '\r');  // for example
    
    istream is(&buff);
    is >> targetstring;
    

    This is a data copy, of course, but that's what you need to do if you want it in a string.

提交回复
热议问题