mardi 5 novembre 2019

issue utilizing the tellp() and tellg() pointers with seekp() and seekg()

I'm attempting to learn how to handle data being received through text files and I'm attempting to utilize this functions to receive the position index of key places;

The code to showcase my issue looks like this:

'''cout << "Program Initiated." << endl << " Testing fileName.get();" << endl << endl;

    fstream fileName("filename", ios::in | ios::out | ios::beg);
    if (!fileName.is_open()) {
            cout << "file didn't open." << endl;
            cin.get();
            return 0;
    }

    fileName.seekp(0, ios::end);
    fileName.seekg(0, ios::beg);

    int endOf = int(fileName.tellp());
    int startOf = int(fileName.tellg());

    cout << "Starting index: " << startOf << endl;
    cout << "End index: " << endOf << endl;'''

As you could see I'm using seekg() and seekp() to place the pointers at the beginning and end of the file respectively. The file does have data in it.

The value shown at the end when executed is the value of whichever seek function I place at the bottom almost as if the changing seekp() also changes seekg() but from what I have understood from the reference material they should be two different pointers.

I would appreciated any guidance you could provide.

Aucun commentaire:

Enregistrer un commentaire