lines in a file
OK last query of theday.
Is there a way to obtain the number of lines in a file?
read my file.
I could just loop through to the end and increase a counter but this seems very inefficient, so thought there must be a better way
> I could just loop through to the end and increase a counter but this seems very inefficient
Yes, that's pretty much the way you do it.
Perhaps you should consider another approach, one which say doesn't rely on knowing the number of lines in advance. That way, you only read the file once instead of twice.
Just a quick note. I have been messing around with compiler options and the __LINE__ macro gives the line# on which it is placed I tried this
and then did a similar thing in each of the header files with a global variable. granted it counts white space and blank lines as well so it prolly isn't what your looking for but I just thought it was cool
unsigned long test=(unsigned long)__LINE__; cout<<test+otherfile; return 0;} //for main