C ++, boost asio, get null terminated string

How can I get a null-terminated string from a socket using boost :: asio library?

+5
source share
1 answer
m_socket = boost::asio::ip::tcp::socket(io_service);
boost::asio::streambuf replyBuf;
...
...
boost::asio::read_until(m_socket, replyBuf, '\0');

And if you want to convert streambuf to string:

std::string retVal((std::istreambuf_iterator<char>(&replyBuf)),
                        std::istreambuf_iterator<char>());
+8
source

All Articles