This C++ program performs string matching using string library of C++. A text and a pattern is given as input. The pattern is searched for in the text and all instances of the pattern are given as output.
This C++ program is successfully compiled and tested on our system. The program output is given below.
* C++ Program to Perform String Matching Using String Library
using namespace std;
std::string org, dup;
int result = -1, i = 1;
std::cout<<"Enter Original String:";
std::cout<<"Enter Pattern String:";
result = org.find(dup, result + 1);
if (result != -1)
} while (result >= 0);
Output Enter Original String:All men went to the appall mall Enter Pattern String:all Instance:1 Position:23 Instance:2 Position:28
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you liked this C++ Program, kindly share, recommend or like below!