So I am having a bit of an issue with making a simple program that can count LOC within itself or other program files. I am making a program that counts all lines except comments, brackets and empty lines. This works, except when it starts to getlines in the main function itself. For example, if you have 35 lines of code and you have 2 comments outside the main function it won't count those comments (output 33 LOC), but it will count those 2 comments if they are inside the main function (output 35 LOC).
find doesn't return 0 when it doesn't find something.
"{" or "}" is a boolean value. You probably want find_first_of on line 27.
Finding a {, } or // on a line is not a good enough reason to dismiss the line. For instance, you would want to count lines 24, 25, 27, 28, 30 31 in your code.
I see what you're saying, but the thing is those if statements work fine actually, just not when counting lines inside the main() function.
Like if I put a comment after "using namespace std;" using "//" it won't dismiss that line in the count (as it should), but it will dismiss a comment line, say if it's below the using namespace. Problem is, it's still count all comment lines, all blank lines, and all bracket only lines inside the main() function.
Works outside but not inside the main function. Baffling to me.
I see what you're saying, but the thing is those if statements work fine actually, just not when counting lines inside the main() function.
The thing is those if statements don't actually work fine, but you're free to keep asserting they do while you wonder what's going wrong.
Let's modify your code and give it the equivalent of a file that consists solely of comments outside of any function and see if your assertion that the code works just fine outside the main function holds true.
Yeah you're right, I researched into find a bit more to learn what it returned. (having to scrap off the rust, been a while since I messed with this!)
But yeah, I instead used the string::npos to test it out and it does fix the one issue, BUT it does bring up another issue that you said would happen. It makes it so my program doesn't count those vital lines, 24, 25, 27, 28, 30 and 31, which should be counted.
Hmm, have to think about it a bit more... Like I said the rust needs to come off.