title: Better way to count things?
body: <p>In one of my programs for school, I use the following function to count the frequency of identifiers in a string, separated by newlines and #:</p>
  
  <p>Input:</p>
  
  <pre><code>dog
  cat
  mouse
  #
  rabbit
  snake
  #
  </code></pre>
  
  <p>Function:</p>
  
  <pre><code>//assume I have the proper includes, and am using namespace std
  vector&lt; pair&lt;string,int&gt; &gt; getFreqcounts(string input) {
      vector&lt;string&gt; items = splitString(input,"\n");
      map&lt;string,int&gt; counts;
  
      for (int i=0; i&lt;items.size(); i++) {
          if (items[i] == "#") continue;
          counts[items[i]] = 0;
      }
      for (int i=0; i&lt;items.size(); i++) {
          if (items[i] == "#") continue;
          counts[items[i]]++;
      }
  
      return vector&lt; pair&lt;string,int&gt; &gt; (counts.begin(),counts.end());
  }
  </code></pre>
  
  <p>I would like to at the very least</p>
  
  <ul>
  <li>remove the double for loop</li>
  <li>find a better way to get a <code>vector&lt; pair&lt;string,int&gt; &gt;</code></li>
  </ul>
  
  <p>Any ideas? </p>
  
  <p>BTW, this is NOT homework. The real homework will use this function, but this is purely out of my own curiosity and desire to have "better" code.</p>