#include <fstream>
#include <iostream>
int main(int argc, char * argv [])
{
std::ifstream f{ "test.syp" };
std::cout << f.tellg() << '\n';
char buffer[4];
f.read(buffer, 4);
std::cout << f.gcount() << '\n';
std::cout << f.tellg() << '\n';
}
When I execute the above code, I get the following output:
0
4
20
If I change ifstream
to fstream
, I get the same thing except that the last number is 21.
I would expect the last number to be 4 in both instances. Why isn't it?
Edit: I get the expected result if I open the file with std::ios::binary
; it must be a quirk of text-mode