字符串包含有效字符

Rav*_*ash 1 c++ stl stdstring

我正在写一个签名的方法

bool isValidString(std::string value)
Run Code Online (Sandbox Code Playgroud)

在这个方法里面我想搜索value属于一组字符的所有字符,这是一个常量字符串

const std::string ValidCharacters("abcd")
Run Code Online (Sandbox Code Playgroud)

要执行此搜索,我从中value搜索并搜索一个字符 ValidCharacters,如果此检查失败,那么它是无效的字符串是否在STL库中有任何其他替代方法来执行此检查.

Geo*_*che 9

用途find_first_not_of():

bool isValidString(const std::string& s) {
    return std::string::npos == s.find_first_not_of("abcd");
}
Run Code Online (Sandbox Code Playgroud)