View Single Post
Old 12-11-2003, 06:02 AM   #1 (permalink)
Prince
/nɑndəsˈkrɪpt/
 
Prince's Avatar
 
Location: LV-426
C++ ifstream pointer question

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;
}
__________________
Who is John Galt?
Prince is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62