在一个String C++中检查几个信号

CJA*_*LEE 2 c++ string

我想在一个字符串中搜索一个不等于"(",")","!","&","|",";"的位置.如果我使用if(str[1] != "!" && str[1] != "(" ...),它太长了...有什么我可以用来使这个简单吗?

Mic*_*ker 5

我想你在谈论find_first_not_of.str.find_first_not_of("!(...").


BoB*_*ish 5

string badChars = "!()&|;";
if ( badChars.find(str[1]) == string::npos )
{
}
Run Code Online (Sandbox Code Playgroud)

编辑:我想我误解了这个问题.正如Michael Krelin所指出的,find_first_not_of可能就是你想要的.