title: How can I count the number of occurrences in a string based on character letter?
body: <p>My code is supposed to take user input of a file with a single string line and user input of the characters within that file and then count the number of occurrences of each character within that string. I have this code so far
  <a href="https://i.stack.imgur.com/853Eg.png" rel="nofollow noreferrer">Working code to count only one of the characters in the string</a>. <a href="https://i.stack.imgur.com/ybefK.png" rel="nofollow noreferrer">The two inputs &amp; Output of the code</a>. <a href="https://i.stack.imgur.com/74PUW.png" rel="nofollow noreferrer">Text File contents</a>. This code allows me to take the user inputs and count the number of occurrences of only one of the characters. My question is how would I be able to loop the count function to count as many times as there are user inputted characters?</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;string&gt;
  using namespace std;
  
  int main()
  {
      //Ask for user input of charcters in file &amp; store in symbols
      char symbols [50];
      string file;
      cin &gt;&gt; symbols;
  
      //Read file name &amp; contents then store in string called values
      cin &gt;&gt; file;
      ifstream document (file);
      string values;
      getline(document,values);
      //cout &lt;&lt; values &lt;&lt; &quot;\n&quot;;
      
      //Search for and count letters in string and then put count in an array named occurances
      char searching = symbols[0];
      int counter = 0;
      int occurances [] = {};  
      for(int i=0;i&lt;values.length();i++)
      {
          if(searching == values[i])
          {
              counter++;
          }
  
       occurances[0] = counter;
      }
      cout &lt;&lt; &quot;Symbol: &quot; &lt;&lt; symbols[0] &lt;&lt; &quot;, Frequency: &quot;&lt;&lt; occurances[0] &lt;&lt; &quot;, Code:  &quot; &lt;&lt; &quot; placeholder&quot; &lt;&lt; endl;
      
      
      return 0;
  
  }
  </code></pre>