I\'m working with this peace of that count the logical lines in a program, omitting comments and black lines. The counting line is working, but I don\'t know how to omit the com
I think your methodology is...flawed.
Consider a line like:
int x = 1; // starting from 1 because [some reason]
As your code stands right now, it counts only as a non-comment line. As you've described what you'd like to do, it would count only as a comment line.
In reality, tThis contains both code and a comment, so you'd normally want to count it as both code and comment, not just one or the other.
Doing this job well is decidedly non-trivial. Obvious problems you encounter are:
#if
s, #ifdef
s, etc.There are probably more issues than that (though are just what occurred to me immediately), but those should be enough to give at least a general flavor.
Bottom line: I think to get very far with this (at all) you're doing to at least need a reasonably complete/accurate C++ lexer. You probably don't need a full parser, but I think any attempt that doesn't use a full C++ lexer s almost certain to fail, probably quite badly and quite frequently.