Is string::compare reliable to determine alphabetical order?

前端 未结 5 1618
太阳男子
太阳男子 2021-02-14 06:59

Simply put, if the input is always in the same case (here, lower case), and if the characters are always ASCII, can one use string::compare to determine reliably the alphabetica

5条回答
  •  感情败类
    2021-02-14 07:47

    According to the docs at cplusplus.com,

    The member function returns 0 if all the characters in the compared contents compare equal, a negative value if the first character that does not match compares to less in the object than in the comparing string, and a positive value in the opposite case.

    So it will sort strings in ASCII order, which will be alphabetical for English strings (with no diacritical marks or other extended characters) of the same case.

提交回复
热议问题