getting the size of an input stream

Started by
0 comments, last by SiCrane 15 years, 11 months ago
Is there a way to get the size of an istream so I can allocate enough memory straight away rather than reallocate say another 64 bytes at a time during copying?
Advertisement
You can use istreambuf_iterators to automagically load an entire istream into a buffer without needing to manually resize it. Ex:
std::istream & istr = get_an_istream_somehow();std::vector<char> buffer( (std::istreambuf_iterator<char>(istr)),                          (std::istreambuf_iterator<char>()) );

This topic is closed to new replies.

Advertisement