Instead of
Is there any elegant way of doing that?Code:while(vec.size() < 65536 && (ch = stream.get(), !stream.eof()))
vec.push_back(ch);
Printable View
Instead of
Is there any elegant way of doing that?Code:while(vec.size() < 65536 && (ch = stream.get(), !stream.eof()))
vec.push_back(ch);
Instead of reading one character at a time, read BUFF_SIZE characters at a time.
You can also directly query the stream buffer:
In either case you use the value to determine how many characters to read in each loop iteration.Code:streambuf * pbuf = stream.rdbuf();
streamsize sizeOfBuffer= pbuf->in_avail()!=0? pbuf->in_avail(): BUFF_SIZE;
/*in_avail gets the expected number of characters available after an underflow, or number of characters in buffer.*/
It is possible to use stream iterators.
I don't remember the exact syntax, but that might help you on the way:
std::copy(std::istream_iterator(stream), std::istream_iterator(), std::back_inserter(vec));