title: count occurrences of specific strings in c++
body: <p>I have a c++ project to count the LLOC of an input file, which is a file generated by a code generator consists of sequence of functions denoted F1( ), F2( ),..., Fn( ), followed by the main program and control structures like if, while, do, switch, and etc. we should count the number of: main program + functions + semicolons + equations + if statements + switch statements + while statements + for statements. I can easily count, for example, the number of ; using find function, but how can I count the number of functions? is there any way to count the substring F*( , which means every substring that starts with F and ends with ( ? </p>
  
  <p>Here is my code to count the number of semicolons:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;fstream&gt;
  
  using namespace std;
  
  int main(int argc, char ** argv) {
      ifstream testfile;
      std::string stringline;
      std::string str2(";");
      size_t found;
      int positioncount = 0;
      char arry[100];
      testfile.open("program.cpp");
      while (!testfile.eof()) {
          testfile.getline(arry, 50);
          stringline = arry;
          if (stringline.find(str2) != std::string::npos) {
              positioncount++;
          }
      }
      cout &lt;&lt; "\n" &lt;&lt; positioncount;
      testfile.close();
      return 0;
  } 
  </code></pre>