I would like to convert a boost::asio::streambuf into a std::string.
How do I do that easily?
views:
771answers:
3
+1
A:
Perhaps this SO answer could be helpful? Depends on what you mean by convert, of course.
Niklas
2009-12-14 09:00:23
A:
Did not try this, but if I read the docs correctly, this class inherits from std::streambuf, in which case you can do this:
std::istream buffer( my_asio_streambuf_ptr );
std::stringstream string_buffer;
buffer >> string_buffer.rd_buf();
There are many ways to do this, and each has it's pros and cons. If you could explain you problem in more detail, we can offer more specific help.
Space_C0wb0y
2009-12-14 09:34:23
A:
Something like this is probably what you're after:
boost::asio::streambuf myBuffer;
std::string myString;
// Convert streambuf to std::string
std::istream(&myBuffer) >> myString;
James M.
2010-03-30 16:42:43