Searching Within Strings using string::find Method - C++ STL

C++ examples for STL:string

Description

Searching Within Strings using string::find Method

Demo Code

#include <iostream> 
#include <string> 

using namespace std; 

int main(int argc, char *argv [])
{   /*from  w w  w  .j a v  a  2  s.  c  o  m*/
        string myString{ "This is my string!" }; 
        size_t found = myString.find("is"); 
        if (found != string::npos) 
        { 
                cout << "\" is\" found at position: " << found << endl; 
        } 
  
        found = myString.find("is", found+1); 
        if (found != string::npos) 
        { 
                cout << "is found at position: " << found << endl; 
        } 
        return 0; 
}

Result


Related Tutorials