I have two questions.
1) How are your the files written? If two-byte integers are written like this:
1 2
|
int16_t x = 259;
outFile.write((const char*)&x, sizeof(x));
|
and you are working on little-endian architecture (most likely you are), then you assemble it in incorrect order (you first read the least-significant byte, but treat it as most-significant one).
Also it is weird that you get any negative values if you only read 2 bytes into (normally) 4-byte integer - the sign is stored in the most significant bit which is never written to and stays zero, signifying that it's a positive number.
2) Are you sure you open your file in binary mode?
So, to sum up. In order to help you, we need to know:
- how the file is written
- what is your architecture
- some other obscure parts of your code :)
PS: use
int16_t
for two-byte integers