C++ Comparison of String Literals

前端 未结 8 613
夕颜
夕颜 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:16

    If you want to compare actual C++ strings, you need to declare C++ strings:

    int main() 
    {
      const std::string a("A");
      const std::string z("Z");
    
      cout << (z < a) << endl; // false
      cout << (a < z) << endl; // true
    }
    

提交回复
热议问题