hellp basic string problem.in 7th line s1>s what does it mean or what it is comparing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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"; }

21st Jun 2018, 2:37 AM
Bahubali
Bahubali - avatar
2 Answers
+ 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.
21st Jun 2018, 3:12 AM
Tanay
Tanay - avatar
+ 2
thanks
21st Jun 2018, 3:24 AM
Bahubali
Bahubali - avatar