boost——string_algo字符串的操作(三)

来源:互联网 发布:网络层 ip层 编辑:程序博客网 时间:2024/05/29 04:40
#include <boost/format.hpp>#include  <boost/algorithm/string.hpp>using namespace boost;using namespace std;int _tmain(int argc, _TCHAR* argv[]){format fmt("|%s|.pos = %d\n") ;string str("Long long ago, there was a king.") ;iterator_range<string::iterator> rge ;//迭代区间rge = find_first(str, "long") ;cout << fmt % rge % (rge.begin() - str.begin()) ;rge = ifind_first(str, "long") ;cout << fmt % rge % (rge.begin() - str.begin()) ;rge = find_nth(str, "ng", 2) ;//第三次出现cout << fmt % rge % (rge.begin() - str.begin()) ;rge = find_head(str, 4) ;cout << fmt % rge  % (rge.begin() - str.begin()) ;rge = find_tail(str, 5) ;cout << fmt % rge  % (rge.begin() - str.begin()) ;rge = find_first(str, "samus") ;assert(rge.empty() && !rge) ;}


这一组查找算法返回返回的iterator_range对象为一个查找区间,可以像原容器一样使用

原创粉丝点击