Finding number of lines between two specified characters.

I am looking for a way to correctly count the lines between two specified characters/strings in a file. Here's the part I need work on:


1
2
3
4
5
6
7
8
9
   
 getline( file, lines );
  
    do {
          if(lines.find("character") 
          {
            ++counter;
          }
       } while( !lines.find("story") );



I want the code to search for the first occurence of the word "character," and start counting the lines from that line until it hit the first occurrence of the word "story."

Right now, I am only getting a counter value of 1.

Thank for you so much for any help.

I hope it's okay that I edited the original thread to this one, I don't want to spam the forum with multiple threads.
Last edited on
1
2
// if( lines.find("();") && (lines.find("void")) != string::npos) {
if( lines.find("();") != string::npos && lines.find("void") != string::npos ) {
Thanks JLBorges, that works a lot better than what I came up with after I posted this.
Topic archived. No new replies allowed.