I'm developing a tcp client using boost::asio to process incoming text, that ends with "\n". However, when I am sending text containing whitespace, it drops all characters after the first whitespace appears. I've already verified that the text I'm sending is complete.
This is my code:
boost::system::error_code error;
boost::asio::streambuf buffer;
boost::asio::read_until( *socket, buffer, "\n", error );
std::istream str(&buffer);
std::string s;
str >> s;
Use std::getline
instead of >>
, which is what stops reading on encountering whitespace:
std::istream str(&buffer);
std::string s;
std::getline(str, s);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With