Saturday 8 April 2017

Comparing two strings without using predefined string functions while using getline function


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

if(s1.size()==s2.size()){
for(unsigned int x=0;x<s1.size();x++){
if(s1[x]!=s2[x]){
count++;
cout<<count;
}
}
if(count==0){
cout<<"strings matched "<<endl;
}
}
else{
cout<<"strings mismatched "<<endl;
}


}

No comments:

Post a Comment