gpt4 book ai didi

c++ - 如何验证用户输入以匹配任何不包含 %、*、等字符的字符串?在 C++11 中

转载 作者:太空宇宙 更新时间:2023-11-03 10:30:52 25 4
gpt4 key购买 nike

我想验证用户输入以匹配任何不包含 %、*、? 等字符的字符串。使用 C++11这些特殊字符在我的输入中是非法的

最佳答案

我想您可以使用正则表达式来做到这一点,但还有一种更简单的方法。您可以使用 std::string::find_first_of()像这样的成员函数:

std::string input;
// ...
bool valid = (input.find_first_of("%*?") == std::string::npos);

关于c++ - 如何验证用户输入以匹配任何不包含 %、*、等字符的字符串?在 C++11 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17197506/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com