#include<iostream>
using namespace std;
#include<conio.h>
#include<string>
void main()
{
string str1("Fawad and Ali ");
string str2("Hallo ");
string str("were studying together ");
string str3;
cout<<"str1:"<<str1<<"\nstr2:"<<str2<<"\nstr:"<<str<<endl;
cout<<"Length of str: ";
cout<<str.length();
cout<<"\nSize of str1: ";
cout<<str1.length();
cout<<"\nis str empty ?: "<<str.empty();
str2.replace(1,1,"e");
cout<<"\nreplacing a with e in str2: str2= "<<str2;
str3=str;
cout<<"\nassigning value of str to str3: str3="<<str3;
str1.append(str3,0,22);
cout<<"\nappending str3 with str1: str1="<<str1;
str2.append(str1,10,4);
cout<<"\nappending some part of str1 with str2: str2="<<str2;
cout<<"\ncharacter in str1 at index 2 is: "<<str1.at(2);
cout<<"\ncomparing ali of str1 with str2: "<<str1.compare(11,3,str2,0,6)<<endl;;
string str5=str1.substr(0,5);
string str4=str1.substr(6,4);
str2=str2+str4+str5;
cout<<"after substrings added: str2="<<str2<<endl;
str1.swap(str2);
cout<<"after swapping str2 with str1:\n str2="<<str2<<"\n str1="<<str1<<endl;
cout<<"First occurence of character A in str2: "<<str2.find("A");
cout<<"\nFirst occurence of character a in str2: "<<str2.find("a");
cout<<"\nFirst occurence of character er in str2: "<<str2.find_first_of("er");
cout<<"\n\n\nlast occurence of character A in str2: "<<str2.find_last_of("A");
cout<<"\nlast occurence of character a in str2: "<<str2.find_last_of("a");
cout<<"\nlast occurence of character er in str2: "<<str2.rfind("er")<<endl;;
cout<<"\n\nindex of wltd: Forward search= "<<str2.find_first_of("wltd");
cout<<"\nindex of wltd: Backward search= "<<str2.find_last_of("wltd")<<endl<<endl;
for(int i=0;i<str2.length();i++)
{
if(str2[i]=='a')
{
cout<<"index of a: "<<i<<endl;
}
}
cout<<"after replacing ali to adil in str1:"<<endl<<str1.replace(6,3,"adil")<<endl;
string str6("auzia,ja");
str2.replace(1,1,str6);
cout<<"inserting auzia,ja in str2:"<<endl<<str2<<endl;
cout<<"after erassing:"<<endl<<str2.erase(6,6);
_getch();
}
using namespace std;
#include<conio.h>
#include<string>
void main()
{
string str1("Fawad and Ali ");
string str2("Hallo ");
string str("were studying together ");
string str3;
cout<<"str1:"<<str1<<"\nstr2:"<<str2<<"\nstr:"<<str<<endl;
cout<<"Length of str: ";
cout<<str.length();
cout<<"\nSize of str1: ";
cout<<str1.length();
cout<<"\nis str empty ?: "<<str.empty();
str2.replace(1,1,"e");
cout<<"\nreplacing a with e in str2: str2= "<<str2;
str3=str;
cout<<"\nassigning value of str to str3: str3="<<str3;
str1.append(str3,0,22);
cout<<"\nappending str3 with str1: str1="<<str1;
str2.append(str1,10,4);
cout<<"\nappending some part of str1 with str2: str2="<<str2;
cout<<"\ncharacter in str1 at index 2 is: "<<str1.at(2);
cout<<"\ncomparing ali of str1 with str2: "<<str1.compare(11,3,str2,0,6)<<endl;;
string str5=str1.substr(0,5);
string str4=str1.substr(6,4);
str2=str2+str4+str5;
cout<<"after substrings added: str2="<<str2<<endl;
str1.swap(str2);
cout<<"after swapping str2 with str1:\n str2="<<str2<<"\n str1="<<str1<<endl;
cout<<"First occurence of character A in str2: "<<str2.find("A");
cout<<"\nFirst occurence of character a in str2: "<<str2.find("a");
cout<<"\nFirst occurence of character er in str2: "<<str2.find_first_of("er");
cout<<"\n\n\nlast occurence of character A in str2: "<<str2.find_last_of("A");
cout<<"\nlast occurence of character a in str2: "<<str2.find_last_of("a");
cout<<"\nlast occurence of character er in str2: "<<str2.rfind("er")<<endl;;
cout<<"\n\nindex of wltd: Forward search= "<<str2.find_first_of("wltd");
cout<<"\nindex of wltd: Backward search= "<<str2.find_last_of("wltd")<<endl<<endl;
for(int i=0;i<str2.length();i++)
{
if(str2[i]=='a')
{
cout<<"index of a: "<<i<<endl;
}
}
cout<<"after replacing ali to adil in str1:"<<endl<<str1.replace(6,3,"adil")<<endl;
string str6("auzia,ja");
str2.replace(1,1,str6);
cout<<"inserting auzia,ja in str2:"<<endl<<str2<<endl;
cout<<"after erassing:"<<endl<<str2.erase(6,6);
_getch();
}