I was going over my notes and found a part that I don't quite seem to understand. We were talking about C++ String processing and I came to a part about relational operators. I can understand how == and != are the same as usage with numbers because it's straight up yes/no as to whether "hello" = "hello", but what exactly does it mean if one string is "less than" another? Does it correspond to length of the string? I'm looking at the examples that are given, but I don't quite understand the pattern. I'm guessing it can't be regarding just the length because I didn't have to use length()?
...
string s1, s2;
cout << "Enter first string: ";
getline(cin, s1);
cout << "Enter second string: ";
getline(cin, s2);
if (s1 == s2)
{
cout << s1 << " equals " << s2 << endl;
}
else if (s1 < s2)
{
cout << s1 << " < " << s2 << endl;
}
else
{
cout << s1 << " > " << s2 << endl;
}
hello < howdy - 4 letters < 5 letters
hello > Howdy - capital letter is less?
HelloWorld > Hello World - blanks are greater?

New Topic/Question
Reply



MultiQuote



|