Is there a better way to determine the length of an std::istream than the following:
std::istream* pcStream = GetSomeStream();
pcStream->seekg(0, ios::end);
unsigned int uiLength = pcStream->tellg();
It just seems really wasteful to have to seek to the end of the stream and then seek back to the original position, especially if the stream might be to a file on some slow media like a CD or DVD.
stat()
on the file. However, it is not any faster than seeking at the end and seeking back at the beginning before reading the contents... that's how file descriptors are implemented. Of course,stat()
is not C++ and it requires a filename... – Mandragora