Boost logo

Boost Users :

Subject: Re: [Boost-users] boost::asio::streambuf question
From: Igor R (boost.lists_at_[hidden])
Date: 2008-10-14 11:57:02


> If(!ec && (bytes_transferred != 0))
>
> {
>
> boost::asio::streambuf::const_buffers_type bufs = buf.data();
>
> std::string
> s(boost::asio::buffers_begin(bufs),boost::asio::buffers_begin(bufs) +
> bytes_transferred);
>
<...>
> My question is how do I clear the contents of buf before calling
> async_read_until again.

If you just want to read some text from from streambuf, do not access
its data() - instead use standard istream methods, like this (the data
you read is removed from the streambuf):

std string someString;
std::istream(&buf) >> someString;
int someStatus;
std::istream(&buf) >> someStatus;
std::string wholeLine;
std::getline(std::istream(&buf), wholeLine);
// and so on...


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net