c++ - Is string::compare reliable to determine alphabetical order? -
Simply put, if the input is always in the same case (here, the short case), and if the character is always ASCII , Can use string: can compare two strings to determine the alphabet sequence?
Thus, if the result is 0 with stringA.compare (stringB)
, then that same, if it is negative, string A stringb comes alphabetically, and if It's positive, what comes after string A? According to the docs at cplusplus.com,
The Member Function 0 returns if the comparison material is made.
Therefore it will sort the strings in ASCII sequence, which will be alphabetical for English strings (without any diacritical digits or otherwise extended characters)
Comments
Post a Comment