The problem is in your code somewhere. Consider the following:
Code:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
using namespace std;
void dump_file(ifstream &fin)
{
char buff[5];
int read;
while (read = fin.rdbuf()->sgetn(buff, sizeof(buff)))
{
cout << '"';
for (int n = 0; n < read; ++n)
{
const char &c = buff[n];
if (::isprint(c))
cout << c;
else
{
if (c == '\r')
cout << "\\r";
else if (c == '\n')
cout << "\\n";
else
cout << "???";
}//else
}//for
cout << "\" tellg = " << fin.tellg() << endl;
}//while
}//dump_file
int main()
{
ifstream fin("data.txt", ios::in | ios::binary);
if (!fin)
{
cerr << "Failed to open file" << endl;
return 1;
}//if
dump_file(fin);
cout << "\n...Resetting to offset 10\n" << endl;
fin.seekg(10, ios::beg);
dump_file(fin);
fin.close();
return 0;
}//main
Data.txt contains "Line1<return>Line2<return>Line3". This is the output I get with both VS 6.0 and VS 2008 (oldest and newest MS CRT's):
Code:
"Line1" tellg = 5
"\r\nLin" tellg = 10
"e2\r\nL" tellg = 15
"ine3" tellg = 19
...Resetting to offset 10
"e2\r\nL" tellg = 15
"ine3" tellg = 19
So in binary mode the file is read byte for byte and absolute file positions work as expected.
gg