trouble with using seekg

Hello,

I am trying to input some data from a .csv file. The data file is 4 columns and any number of rows. I am trying to count the number of rows and then extract the data. The code will count the rows but then I try to use seekg to start from the beginning of the file but it isn't working as I expect it to

a snippet of the code is

1
2
3
4
5
6
7
8
9
10
11
12
ifstream inputFile;
inputFile.open("testFile.csv");

while( inputFile.is_good() )
{
    if( inputFile.get() == '\n' )
        nRowCounter++;
}

inputFile.seekg(0, ios::beg);
cout << inputFile.tellg() << endl;


I was hoping this would take me back to the start of the file but it doesn't seem to be doing that.

Any ideas of where I am going wrong
Cheers.
You could try to put inputFile.clear(); on line 9 but I'm not sure if seekg works on text files.
Excellent, worked a treat, thank you!

Topic archived. No new replies allowed.