Comparing strings

Hi I'm having trouble with this while loop, I'm trying to make it read multiple inputs from two different strings and see if they're the same or not. So far I got it to read one line Ex: string one: Hey
string two: Hi
output: No (meaning they're different)
If I try to input "hey how are you doing" it won't let me input the second string to compare and just says "no"

Here's the loop

while(str1.length() !=0)
{
if(str1==str2)
cout<<"Yes"<<'\n';
else
cout<<"No"<<'\n';

return 0;
}
Hi,
I hope str1 and str2 are string type variable.
If they are of type string then why you required while loop?

Because string can directly compare by using operator(==).
Hi,

Well I tried this before, basically making tokens from a string, but it would only read the first line separated by a comma, so I thought making it really simple would help but it didn't..

while (f!= NULL && q!= NULL)
{
int result = strcmp(f,q);
if ( result == 0 )
cout <<"Yes" << endl;
else if ( result != 0 )
cout <<"No" << endl;

f = strtok(NULL,",");
q = strtok(NULL,",");
}

return 0;
}
What I understood is you have two strings like,
1
2
string str1 = "Hey, Whats up?";
string str2 = "Hey, Hows going?";


And you want to compare these two strings are equal or not,
If not equal then which sub string is not equal that you have to find?
is it correct?
Yes! This is correct!
Topic archived. No new replies allowed.