将字符串变量与一组字符串常量进行比较的最佳方法是什么?

mkn*_*ght 1 c++ string compare constants

if声明看起来太尴尬,因为我需要增加常数的可能性.很抱歉让你因为"常数"而不是我的意思而陷入妄想.

Gle*_*len 9

将所有常量添加到std :: set,然后您可以检查该集合是否包含您的字符串

std::set<std::string> myLookup;
//populate the set with your strings here

set<std::string>::size_type i;

i = myLookup.count(searchTerm);
if( i )
    std::cout << "Found";
else 
    std::cout << "Not found";
Run Code Online (Sandbox Code Playgroud)