Hi, everybody. It's been a while since my last post.

I'm working with the MinGW GCC tool chain in Eclipse, which works perfectly about half the time. For some mysterious reason, when I do file read/write operations using seekg(), seekp(), tellg(), and tellp(), my code behaves very poorly.

For example, take this code into consideration:
Code:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
    using namespace std;

    ifstream inf("Sample.dat");

    // If we couldn't open the input file stream for reading
    if (!inf)
    {
        // Print an error and exit
        cerr << "Sample.dat could not be opened for reading!" << endl;
        exit(1);
    }

    string strData;

    inf.seekg(5, ios::beg);         // move to 5th character

    getline(inf, strData);	// Get the rest of the line and print it
    cout << strData << endl;

    inf.seekg(8, ios::cur);          // move 8 more bytes into file

    getline(inf, strData);	// Get rest of the line and print it
    cout << strData << endl;

    inf.seekg(-15, ios::end); 	// move 15 bytes before end of file

    getline(inf, strData);            // Get rest of the line and print it
    cout << strData << endl << endl;

    return 0;
}
Sample.dat contents:


This is line 1
This is line 2
This is line 3
This is line 4
[Line 5 is a newline]


This code isfrom a C++ tutorial on basic random file IO. It compiled and ran perfectly on the author's machine. I have the file, and the program compiles and runs on my system. The problem is that the file pointer seems to get messed up. The first line of output is correct for me. The second two are horribly wrong! This problem has been corrupting all of my advanced file IO programs.

Here is the intended output:

is line 1
line 2
This is line 4


Here is what I get:

is line 1
e 2
his is line 4


Like I said, the file pointer gets a little confused about its intended position. What am I missing here?