您能帮我找出我从下一行中取出的这 2 行有什么错误吗?由于我是 C++ 的新手,我需要你们的帮助。另外,如何将此代码更改为c++,因为我习惯于C编程语言而不是C++
fgets(线,80,在)
错误:倒带(在);行 = countLines(in);
代码:
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;
}