+ 1
hellp basic string problem.in 7th line s1>s what does it mean or what it is comparing?
#include <iostream> using namespace std; int main() { string s,s1; cin>>s; cin>>s1; if(s1>s) cout<<"YES"; else cout<<"NO"; }
2 Réponses
+ 5
it compares both string character by character.
for example:
if s = "Hello" and s1 = "Hello"
then Returns 0(false) so it means strings are the same
or
if s="Hello" and s1="Hi"
then first character are the same so difference is zero so it compares the next characters which are 'e' and 'i' since assci code of 'i' is greater than the assci code of 'e'. so difference between assci code of 'i' - 'e' is positive so returns true if the difference between assci was negative then it will return false.
+ 2
thanks