Hi there,
I am having a problem with the following code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int findRows( string line );
int main()
{
string line;
int rows = findRows( line );
cout << "Number of rows: " << rows << endl;
}
int findRows( string line )
{
int Rows = 0;
ifstream inData; // Create new input file stream object
inData.open( "input.dat" );
if ( !inData )
cout << "Error in opening file" << endl;;
return 0;
while( getline( inData, line ) ) // While there is still a line, add number of rows
{
Rows++;
cout << line << endl;
}
return Rows;
}
The file doesn't seem to open, but displays the error message. However, it works if I move the above function code into main. How do I fix this?
Thanks :)