problem with seekg(), a strange one

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • geseeker
    New Member
    • Jul 2008
    • 2

    problem with seekg(), a strange one

    Hi, i want to move the file pointer to the last 128th byte, so i can read the ID3V1 tag in an mp3 file. Here's my code to test the result of moving the file pointer:

    #include <iostream>
    #include <fstream>
    using namespace std;

    int main()
    {
    ifstream fin("tagTest.mp 3");
    char c;

    fin.seekg(-128, ios_base::end);
    cout << fin.eof()<< " " << hex << fin.tellg() << endl;
    cin.get();
    return 0;
    }

    and strangely, it always yields the result
    0 0

    i don't know why, i used seekg(-128, ios_base::end) and nothing happened! the file pointer still points to the beginning of the file. i tried using clear() function but it still doesn't work. Can someone pls help me with this problem? Thanks.

    oh, by the way, i'm using Borland C++ Builder 6.
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    R u opening the file in binary mode?


    Raghu

    Comment

    • geseeker
      New Member
      • Jul 2008
      • 2

      #3
      wow, it works when i open the file in binary mode, thanks!
      i spent a whole day trying to figure out the reason. you've been really helpful!

      Comment

      Working...