getting the size of an input stream
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?
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
Popular Topics
Advertisement