count number of occurrences of a string in a vector of string
<p>My requirement is to count the number of occurences of a string inside a vector of string. The string to be searched is at 0th index of the vector. </p>

<p>I am using the inbuilt <code>count</code> function from <code>algorithm</code> header, but getting a weird compilation error, which I am not able to resolve.</p>

<p>My Code:</p>

<pre><code>vector&lt;string&gt; a={"abc", "def", "abc"};
int cnt = count(a.begin(), a.end(), a[0]);
</code></pre>

<p>Compilation error message is:</p>

<pre><code>count(std::vector&lt;std::basic_string&lt;char&gt; &gt;)':
error: no matching function for call to std::vector&lt;std::basic_string&lt;char&gt; &gt;::iterator, std::vector&lt;std::basic_string&lt;char&gt; &gt;::iterator, __gnu_cxx::__alloc_traits&lt;std::allocator&lt;std::basic_string&lt;char&gt; &gt; &gt;::value_type&amp;)'
  int cnt = count(a.begin(), a.end(), a[0]);
</code></pre>

<p>Any help? What is the issue here?</p>