#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(); }
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<conio.h>
#include<string>
usingnamespacestd;
voidmain()
{
intfind;
stringsb2,fn1;
strings1="Yes, we went to Gates after we left the room";
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.
1 Response
[…] Program to find a substring within a string. If found display its starting position […]