Use count on string : count « STL Algorithms Non modifying sequence operations « C++






Use count on string

  
 

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
  string str1("Strings handling is easy in C++");
  string::iterator p;
  unsigned int i;

  // use the count() algorithm
  i = count(str1.begin(), str1.end(), 'i');
  cout << "There are " << i << " i's in str1\n";

  return 0;
}
/* 
There are 4 i's in str1

 */
        
    
  








Related examples in the same category

1.count true value in a vector
2.Use count function and print elements with value 4
3.Use count function to count elements with even value
4.Use count function to count elements that are greater than value 4
5.Create a reciprocal function object with transform() and customized function
6.Use count() with vector of boolean value