Could you help me find what is error with this 2 line which I took from the below line. Since I am a newbie in c++, I need your help folks. In addition, how to change this code to c++ because I am used to C programming language rather than C++
fgets( line, 80, in )
error : rewind( in ); rows = countLines(in);
Code:
int container:: countLines( ifstream in )
{
int count = 0;
char line[80];
if ( in.good())
{
while ( !in.eof() )
if (in>>line ) count++;
rewind( in );
}
return count;
}
// opens the file and stores the strings
//
// input: string of passenger data
// container to store strings
//
int container:: processFile( char* fn )
{
char line[80];
ifstream in ;
in.open(fn);
int count = 0;
if ( !in.fail() )
{
rows = countLines(in);
strings = new char* [rows];
while ( !in.eof() )
{
if ( in>>line )
{
strings[count] =new char [strlen(line)+1];
strcpy(strings[count],line);
count++;
}
}
}
else
{
//printf("Unable to open file %s\n",fn);
//cout<<"Unable to open file "<<fn<<endl;
exit(0);
}
in.close();
return count;
}