+ 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; }
4 odpowiedzi
0
use;-
i = strcmp(str1.c_str(), str2.c_str());
or use:-
i = str1.compare(str2);
0
rodwynnejones Its working fine, Thank you❤
But why i got error in my previous code & what's the changing?
0
strcmp() needs a "c style" string, that why I "converted" it with the "c_str().
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?