简体   繁体   English

在迭代器中使用升压字符串算法

[英]Using boost strings algorithms with iterators

I have a string defined with 2 iterators. 我有2个迭代器定义的字符串。 I want to check, if it ends with some string. 我想检查一下是否以某些字符串结尾。 Now my code looks like 现在我的代码看起来像

algorithm::ends_with(string(begin,end),"format(");

Is there some way to execute this function without constructing a string? 有什么方法可以在不构造字符串的情况下执行此功能? Something like 就像是

algorithm::ends_with(begin,end,"format(");

Yes. 是。

 std::string s = "something";
 bool b = boost::algorithm::ends_with( &s[0], "g");  // true

Iterator can be used to construct a range as well: 迭代器也可以用于构造范围:

#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

or: 要么:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM