Search for a single character in a string using find_first_of. - C++ STL

C++ examples for STL:string

Description

Search for a single character in a string using find_first_of.

Demo Code

#include <iostream> 
#include <string> 

using namespace std;

int main(int argc, char *argv[])
{
  string myString{ "This is my string!" };

   int found = myString.find_first_of("msg");
  if (found != string::npos)
  {/*from   ww w.  ja  va 2 s .c om*/
    cout << "is found at position: " << found << endl;
  }
  return 0;
}

Result


Related Tutorials