How do I count the lines for the method and object. I can't figure it out.

Pages: 12
On line 47 and 49 use line instead of filename, just for the other two count methods.
And yes, double quotes around class and ::, remember, characters get single quotes, strings get double quotes.
Last edited on
When I changed it like this it gave me 0 though
1
2
3
4
5
6
7
8
9
10
11
12
void LOC::countLines(){
    ifstream myfile(line.c_str());

	while (getline(myfile, line)){
		//ignore lines that are either blank or /
		if(filename.empty() || (filename.find("//")==0)){
			continue;
		}        
		//increment lines of number count
        numLines++; 
    }
	myfile.close();
Last edited on
Line 6 you're still trying to search the filename instead of the string pulled from the file. Replace filename with line on line 6.
It still outputs 0 when I did that
Is it because of how I try to output it?
Find doesn't return a boolean valu, do this instead: (line.find("//") != line.npos)

I got it to work kinda... thanks pnoid!
it outputs the number of lines correctly but for the class and :: it outputs 1 extra
Last edited on
Topic archived. No new replies allowed.
Pages: 12