C++ Programming Code Examples C++ > Strings Code Examples Program to Perform String Matching Using String Library Program to Perform String Matching Using String Library 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. #include <iostream> #include <string> using namespace std; int main() { std::string org, dup; int result = -1, i = 1; std::cout<<"Enter Original String:"; getline(std::cin, org); std::cout<<"Enter Pattern String:"; getline(std::cin, dup); do { result = org.find(dup, result + 1); if (result != -1) std::cout<<"\nInstance:"<<i<<"\tPosition:"<<result<<"\t"; i++; } while (result >= 0); return 0; }