SWAPPING TWO STRINGS WITHOUT USING PREDEFINED STRING FUNCTIONS

#include<iostream>
#include<string>
using namespace std;
int main(){
string s1,s2;
int count=0;
cout<<"Manually comparing two strings "<<endl;
cout<<"string s1 = ";
getline(cin,s1);
cout<<"string s2 = ";
getline(cin,s2);

string temp=s1;
s1=s2;
s2=temp;

cout<<"after swapping "<<endl;
cout<<endl<<"string s1 = "<<s1<<endl;
cout<<endl<<"string s2 = "<<s2<<endl;
}


Previous
Next Post »

Comments:

Disqus Shortname