First of all std::basic_istream::tellg reports the current position of the get pointer (current read position in the stream) which refers to a stream buffer what you want is std::basic_istream::gcount which returns the number of characters read during the last unformatted input (there not the same), basically how many bytes read from last unformatted I/O op.
The number -1 that std::basic_istream::tellg returns is indicating that I/O has failed & the failbit has been set, you should check the state of the stream after each I/O operation or turn exceptions on for a stream. I can not say i'm 100% sure of why your getting the problem but i have some suggestions:
A: Opened the stream in text mode.
B: Incorrectly read the variable nNumTriangles from file.
C: Alignment and padding by the compiler is messing you up, you want to make sure you have one byte alignment, you can force the compiler to align this is different for every compiler so check documentation.
i also sugggest that you read in all ms3d_triangle_t in one go:
std::vector<ms3d_triangle_t> tris;//....tris.reserve(nNumTriangles);if(!fin.read(reinterpret_cast<char*>(&tris[0]), sizeof(ms3d_triangle_t) * nNumTriangles)) { //do error handling}
[Edited by - snk_kid on January 17, 2005 4:22:07 AM]