How to compare strings

前端 未结 3 1324
悲哀的现实
悲哀的现实 2020-12-10 00:55

I wanted to compare a string without actually defining one of them as a string, something like this,

if (string == \"add\")

Do I have to de

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 01:24

    In C++ the std::string class implements the comparison operators, so you can perform the comparison using == just as you would expect:

    if (string == "add") { ... }
    

    When used properly, operator overloading is an excellent C++ feature.

提交回复
热议问题