[英]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.