#include<iostream>
#include<conio.h>
#include<string>
using namespace std;
class String
{
protected:
string str;
char Rplce[100];
string Search;
int location;
public:
void SetStr(string st)
{
str=st;
}
string getstr()
{
return str;
}
};
class Find_Locaton:public String
{
public:
void SetSrc(string st)
{
Search=st;
}
int Find_loca()
{
location=str.find(Search);
if(location!=string::npos)
{
return location;
}
else
{
return -1;
}
}
void Rplace_String()
{
cout << "Enter String You Want to replace : ";
cin >> Rplce;
int i=0;
while(Rplce[i]!='\0')
{
i++;
}
str.replace(Find_loca(),i,Rplce);
cout << str;
}
};
int main()
{
Find_Locaton lc;
string srch;
cout << "Enter String for serach....";
cin >> srch;
lc.SetSrc(srch);
lc.SetStr("he is a good");
cout << " Location Found : "<<lc.Find_loca() << endl;
lc.Rplace_String();
getch();
return 0;
}
#include<conio.h>
#include<string>
using namespace std;
class String
{
protected:
string str;
char Rplce[100];
string Search;
int location;
public:
void SetStr(string st)
{
str=st;
}
string getstr()
{
return str;
}
};
class Find_Locaton:public String
{
public:
void SetSrc(string st)
{
Search=st;
}
int Find_loca()
{
location=str.find(Search);
if(location!=string::npos)
{
return location;
}
else
{
return -1;
}
}
void Rplace_String()
{
cout << "Enter String You Want to replace : ";
cin >> Rplce;
int i=0;
while(Rplce[i]!='\0')
{
i++;
}
str.replace(Find_loca(),i,Rplce);
cout << str;
}
};
int main()
{
Find_Locaton lc;
string srch;
cout << "Enter String for serach....";
cin >> srch;
lc.SetSrc(srch);
lc.SetStr("he is a good");
cout << " Location Found : "<<lc.Find_loca() << endl;
lc.Rplace_String();
getch();
return 0;
}