compare two string in C++ by R4R Team

Here we compare two string that they are equal or not.

program:

#include< iostream>
int main()
{
char ch1[20],ch2[20];
int i=0;
//input of string
cout<<"Enter first string"<< endl;
cin>>ch1;
cout<<"Enter second string"<< endl;
cin>>ch2;
while(ch1[i]!='' || ch2[i]!='')
{
if(ch1[i]!=ch2[i])
{
cout<<"Not same";
i=-1;
break;
}
i++;
}
if(i!=-1)
cout<<"Same";
}


output-

Enter first string
Mystring
Enter second string
Mystring
Same

Enter first string
Mystring
Enter second string
My
Not same

-In this program, we take an input of two string and run the loop and check each and every character that it is equal or not.




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!