-3

I'd like to jump/loop through to the last line of a text file, read only the first character from that line and store it within an int called "id". Can somebody please explain how I would achieve this? The content of the text file is as follows:

1 Chris Boy 5
2 Stephanie Girl 8
3 Zack Boy 1
cvandal
  • 764
  • 5
  • 18
  • 31
  • Check this post about how to read only last line of file: http://stackoverflow.com/questions/11876290/c-fastest-way-to-read-only-last-line-of-text-file – taocp Apr 30 '13 at 02:51

1 Answers1

-1

I managed to work this out using the link tacp provided. My code is as follows:

if (inStream.is_open())
    {
        inStream.seekg(-1, ios_base::end);

        getline(inStream, lastLine);

        id = stoi(lastLine);

        id = id + 1;
    }
    else
    {
        cout << "Unable to open staffMembers.txt.\n";
        exit(1);
    }
cvandal
  • 764
  • 5
  • 18
  • 31