[C++]Comparing Strings Using Equality Operators.
I'm reading an example and I am trying to think about how this would make sense. It's probably something simple, I just am a little confused.I'm trying to figure out if one of my strings in greater than the other using the method above. The program compiles and runs, but I don't understand the result I am getting.
Code:
#include <iostream>
#include <string>
using namespace std;
int main(){
string first, second;
cin >> first >> second;
if(first > second)
cout << "Correct." << endl;
else
cout << "Incorrect." << endl;
system("Pause");
return 0;
}
My input was "country" and "applesauce" respectively.
The output is saying "Correct." but I don't understand how "country" is greater than "applesauce." I've tested it with other words as well and sometimes the shorter word is greater and sometimes the larger word is greater. How is it determined?
Thank you for reading.
Last edited by Carpentr; December 15th, 2011 at 07:25 AM.
AMD FX-9590 4.7Ghz, 256GB SSD, 2TB 7200RPM, nVidia 970 GTX, 16GB DDR3
Bookmarks