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
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.*/
Last edited by King Mir; 08-14-2011 at 02:33 AM.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.