Why isn't (“Maya” == “Maya”) true in C++?
问题 Any idea why I get "Maya is not Maya" as a result of this code? if ("Maya" == "Maya") printf("Maya is Maya \n"); else printf("Maya is not Maya \n"); 回答1: Because you are actually comparing two pointers - use e.g. one of the following instead: if (std::string("Maya") == "Maya") { /* ... */ } if (std::strcmp("Maya", "Maya") == 0) { /* ... */ } This is because C++03, §2.13.4 says: An ordinary string literal has type “array of n const char ” ... and in your case a conversion to pointer applies.