Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在编写一个签名为的方法
bool isValidString(std::string value)
在这个方法中,我想搜索所有字符value都属于一组字符,它是一个常量字符串
value
const std::string ValidCharacters("abcd")
为了执行此搜索,我从中获取一个字符 value并搜索ValidCharacters,如果此检查失败,则它是无效字符串 STL 库中是否有任何其他替代方法可以执行此检查。
ValidCharacters
使用find_first_not_of():
find_first_not_of()
bool isValidString(const std::string& s) { return std::string::npos == s.find_first_not_of("abcd"); }
您可以使用正则表达式进行模式匹配。库 regexp.h 将被包括在内
http://www.digitalmars.com/rtl/regexp.html