[英]Using boost strings algorithms with iterators
我有2个迭代器定义的字符串。 我想检查一下是否以某些字符串结尾。 现在我的代码看起来像
algorithm::ends_with(string(begin,end),"format(");
有什么方法可以在不构造字符串的情况下执行此功能? 就像是
algorithm::ends_with(begin,end,"format(");
是。
std::string s = "something";
bool b = boost::algorithm::ends_with( &s[0], "g"); // true
迭代器也可以用于构造范围:
#include <boost/range.hpp>
std::string s = "somet0hing";
std::string::iterator it = s.begin();
bool b = boost::algorithm::ends_with(
boost::make_iterator_range( it, s.end()), "g"); // true
要么:
std::string s = "somet0hing";
std::string::iterator it = s.begin();
bool b = boost::algorithm::ends_with( &(*it), "g"); // true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.