+ 1

What's wrong here?

I'm getting error here: #include <bits/stdc++.h> using namespace std; int main() { string str1, str2; int i; cin >> str1 >> str2; i= strcmp(str1, str2); cout << i << endl; return 0; }

3rd May 2020, 6:41 PM
Ashfaq Reshad
Ashfaq Reshad - avatar
4 odpowiedzi
0
use;- i = strcmp(str1.c_str(), str2.c_str()); or use:- i = str1.compare(str2);
3rd May 2020, 6:49 PM
rodwynnejones
rodwynnejones - avatar
0
rodwynnejones Its working fine, Thank you❤ But why i got error in my previous code & what's the changing?
3rd May 2020, 6:53 PM
Ashfaq Reshad
Ashfaq Reshad - avatar
0
strcmp() needs a "c style" string, that why I "converted" it with the "c_str().
3rd May 2020, 9:20 PM
rodwynnejones
rodwynnejones - avatar
0
rodwynnejones this code giving me some garbage value for some test cases: #include <bits/stdc++.h> using namespace std; int main() { string str1, str2; int i; cin >> str1 >> str2; i= str1.compare(str2); cout << i << endl; return 0; } for this test case: abcdefg AbCdEfF abs Abz aaaa aaaA these test cases giving me garbage value. What can i do here?
4th May 2020, 3:52 AM
Ashfaq Reshad
Ashfaq Reshad - avatar