Meryl Silverburgh wrote: <snip>
I guess a bigger problem for me for using lexicographical_compare is I will get opposite result depends on the order of the input string: For example, if I have string s1("/1/9"), string s2("/1/9/3");
the compare will return true,
but if I have
string s1("/1/9/3"), string s2("/1/9");
it will return false.
But for my case, I always want "/1/9" less than "/1/9/3"
I guess I can compare the length of the 2 string and always put s1 to be the shorter one, and s2 to be the longer one.
if there is an more efficient/cleaner idea, please let me know.
Here is an excert from the lexicographica_compare documentation in msdn: <quote> A lexicographical comparison between sequences compares them element by element until: It finds two corresponding elements unequal, and the result of their comparison is taken as the result of the comparison between sequences. No inequalities are found, but one sequence has more elements than the other, and the shorter sequence is considered less than the longer sequence. No inequalities are found and the sequences have the same number of elements, and so the sequences are equal and the result of the comparison is false. </quote> So the lexicographical_compare does indeed take the lenght of sequences into account. The problem you see, is due to the nature it handles you the result. If lexc(a,b) returns true, you know that a