that's because the loop is wrong. You don't need to use eof() at all
while( getline(inData, line) )
{
size++;
// do other stuff here
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
you do not have to close and then reopen the file; inData.clear() ; inData.seekg(0) ; is more efficient.
> I need the number of lines before I can correctly do the other stuff.
you do not; use a vector instead of a c-style array:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std ;
int main()
{
ifstream file( __FILE__ ) ;
string line ;
vector<string> lines ;
while( getline( file, line ) ) lines.push_back( line ) ;
cout << "#lines: " << lines.size() << '\n' ;
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287