C++ examples for STL:string
Searching Within Strings using string::find Method
#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; }