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.
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Information Technology Internship
- Buy Computer Science Books
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Apply for C++ Internship