Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost: read_until "\n" reads until " "

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; 
like image 283
Pedro Avatar asked Dec 09 '22 05:12

Pedro


1 Answers

Use std::getline instead of >>, which is what stops reading on encountering whitespace:

std::istream str(&buffer); 
std::string s; 
std::getline(str, s);
like image 171
Jon Avatar answered Dec 11 '22 19:12

Jon