简体   繁体   中英

Using boost strings algorithms with iterators

I have a string defined with 2 iterators. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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