字符串迭代器中是否有类似 find_first_of on string 的方法? 像这样的东西:
string::iterator it;
string str(" h asdasf ^& saafa");
it = FIND_FIRST_OF("&az^");
std::cout << *it << std::endl;
结果:
a
最佳答案
你可以间接地做到这一点
auto pos = str.find_first_of("&az^");
然后推进迭代器
if(pos != std::string::npos) // thanks to @Mike Seymour
std::advance(it, pos);
我猜你也可以用 lambda 做一些std::find
,但上面的代码确实更简单和简洁。
关于C++ 字符串迭代器 "find first of",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30173767/