Here's the code, i just want to count the lines of a file. I get a bunch of "invalid simple type name destructor" errors..
It makes a pointer to an input stream to the file specified by the command line parameter. Then it passes the pointer to countlines() to try to count the lines. anyone know why it doesn't work?
Quote:
#include <fstream.h>
#define NULL 0
#define WIDTH 257
int countlines(ifstream *in);
int main(int numArgs, char *args[])
{
if (numArgs != 2)
{
cout << "Usage:\n reader filename.ext";
return 1;
}
ifstream *fin;
fin = new ifstream(args[1], ios::in | ios::nocreate);
cout << countlines(fin);
//char buf[WIDTH];
//for(int i=0; !*fin.eof(); i++)
//{
// *fin.getline(buf, WIDTH);
// cout << buf << "\n";
//}
//
*fin.close();
return 0;
}
int countlines(ifstream *in)
{
int lines = 0;
char null[WIDTH];
while (!*in.eof())
{
*in.getline(null, WIDTH);
lines++;
}
*in.seekg(0, ios::beg);
delete null;
return lines;
}
|