Friday, 24 November 2017

C++ Program to Perform String Matching Using String Library


Code:

#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++;
    } while (result >= 0);
    return 0;
}


Output:

Enter Original String:All men went to the appall mall
Enter Pattern String:all

Instance:1      Position:23
Instance:2      Position:28


More C++ Programs:

















100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...