Reputation: 537
So after I use async_read_until
to read until a delimiter there is some extra data that is left in the buffer and I have been trying to read it like this
void Connection::read_left_over(std::string &req, size_t &bytes) {
std::istream_iterator<char> itr(this->input_stream);
std::cout << buffer_.in_avail() << std::endl; // returns the size of the data with spaces
bytes -= size_t(buffer_.in_avail());
req.append(itr, std::istream_iterator<char>());
std::cout << buffer_.in_avail() << std::endl; // returns 0
std::cout << req << std::endl;
}
But the issue is the text that is been read is stripped of spaces, although before reading the buffer says it has a data with spaces and after the read it returns 0. Is there any reason to why this happening and if so a way to overcome this?
Upvotes: 1
Views: 286
Reputation: 393789
This is behaviour of istream. You can get other behaviour using
std::getline
std::streambuf_iterator
stream >>
std::noskipws
manipulator (which ends up calling stream.unsetf(std::ios::skipws)
under the hood)Upvotes: 1