find_first_of

Syntax:

    #include <string>
    size_type find_first_of( const string &str, size_type index = 0 );
    size_type find_first_of( const char* str, size_type index = 0 );
    size_type find_first_of( const char* str, size_type index, size_type num );
    size_type find_first_of( char ch, size_type index = 0 );

The find_first_of function either:

For example, the following code uses find_first_of to replace all the vowels in a string with asterisks:

  string str = "In this house, we obey the laws of thermodynamics!";
  size_type found = str.find_first_of("aeiouAEIOU");
 
  while( found != string::npos ) {
    str[found] = '*';
    found = str.find_first_of("aeiouAEIUO",found+1);
  }
 
  cout << str << '\n';  // displays "*n th*s h**s*, w* *b*y th* l*ws *f th*rm*dyn*m*cs!"

Related Topics: find, find_first_not_of, find_last_not_of, find_last_of, rfind