Is string::compare reliable to determine alphabetical order?

前端 未结 5 1718
太阳男子
太阳男子 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条回答
  •  萌比男神i
    2021-02-14 07:52

    yes,

    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.

    For string objects, the result of a character comparison depends only on its character code (i.e., its ASCII code), so the result has some limited alphabetical or numerical ordering meaning.

提交回复
热议问题