Program to find a substring within a string. If found display its starting position

Program to find a sub string within a string

Program to find a substring within a string. If found display its starting position

Object: Write a program to find a sub string within a string. If found display its starting position. C++ projects for beginners with source code

Code:

#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
void main()
{
int find;
string sb2,fn1;
string s1=”Yes, we went to Gates after we left the room”;
cout<<s1;
cout<<“\nEnter substring which you find: “;
getline(cin,sb2);
find=s1.find(sb2);
fn1=s1.substr(find,’sb2′);
cout<<endl<<“Substring is: “<<fn1;
cout<<endl<<“Substring Position is: “<<find;
getch();
}

Output:

Program to find a substring within a string. If found display its starting position

M.A Siddiqui

Hi, I am M.A Siddiqui. I'm a Computer Science Student, In this website, I'm teaching you Multiple languages and provides Projects and other Subjects Notes.

You may also like...

1 Response

  1. June 14, 2020

    […] Program to find a substring within a string. If found display its starting position […]

Leave a Reply

Your email address will not be published. Required fields are marked *