Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <iostream>

#include<string.h>

using namespace std;

int main()
{
string s1;
string s2;
string s3;
cout<<"Enter first string"<<endl;
getline(cin,s1);
cout<<"Print s1:"<<s1<<endl;
cout<<"Enter second string"<<endl;
getline(cin,s2);
cout<<"print s2:"<<s2<<endl;

// copy s1 into s3
s3=s1;
cout<<"Print s3 after copy:"<<s3<<endl;

// concatenation
s3=s2+s1;
cout<<"Print concatenation of s1 and s2:"<<s3<<endl;

//compare string
int x;
x=s1.compare(s2);
if(x==0)
{
cout<<"string are same:"<<endl;
}
else
{
cout<<"string are different."<<endl;
}

// insert element

s1.insert(2,s2);
cout<<"Print s1 string after insertation::"<<s1<<endl;

// replace string

s1.replace(1,3,s2);
cout<<"Print s1 element after replacing::"<<s2<<endl;

// sub array

s3=s1.substr(2,5);
cout<<"Print the sub array="<<s3<<endl;

//erase array

s1.erase(2,3);
cout<<"print the s1 after erase"<<s3<<endl;

// swipe array
s1.swap(s2);
cout<<"After swiping s1 is:"<<s1<<endl;
cout<<"After swiping s2 is :"<<s2<<endl;

You might also like