After the loop, you just multiply the count integer with the amount of bytes read per read call (probably 1? ;))
I'm not sure if it is better or worse, but I like this method much more:
stream.seekp(0, std::ios::end); // find eof
size_t size = stream.tellp(); // this actually provides the real size
stream.seekp(0); // find start
char* buffer = new char[size]; // allocate space
stream.read(buffer, size); // read it all in at once
stream.close(); // done :D
Note: seekp and tellp may be seekg and tellg.
Can't remember whether p or g version is for ifstream.
Actually, I'm reading in 1024 byte chunks, and sending the 1024 bit buffer over winsock each read, so I need a way to communicate how many characters the last buffer actually holds, if not the entire 1024 bytes
I have to go with Ancient though...I tried using tellg(),but tellg() reads -1 once you have read past the end of the file, because it returns the next char that will be read, not the last one that was read, which of course doesn't exist after EOF =(
thanks again, gcount() is exactly what I needed =)