C++ Comparison of String Literals

前端 未结 8 617
夕颜
夕颜 2020-11-27 06:01

I\'m a c++ newbie (just oldschool c). My son asked for help with this and I\'m unable to explain it. If he had asked me \"how do I compare strings\" I would have told hi

8条回答
  •  囚心锁ツ
    2020-11-27 06:13

    The string constants ("A" and "Z") in C++ are represented by the C concept - array of characters where the last character is '\0'. Such constants have to be compared with strcmp() type of function.

    If you would like to use the C++ std::string comparison you have to explicitly state it:

    cout << (std::string( "A") < "Z");
    

提交回复
热议问题