Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1469483
  • 博文数量: 218
  • 博客积分: 6394
  • 博客等级: 准将
  • 技术积分: 2563
  • 用 户 组: 普通用户
  • 注册时间: 2008-02-08 15:33
个人简介

持之以恒

文章分类

全部博文(218)

文章存档

2013年(8)

2012年(2)

2011年(21)

2010年(55)

2009年(116)

2008年(16)

分类: C/C++

2009-06-20 19:14:44

反向迭代器reverse_Iterator的表示范围,以及反向迭代器和正向Iterator的转化关系见下图:
反向Iterator执行自增操作是向前移动,自减是向后移动
下面是一个使用Reverse_Iterator将一个句子进行反向输出的例子
    std::string line = "Nothing is impossible";
    std::string::reverse_iterator findIt;
    std::string::reverse_iterator tempIt = line.rbegin();
    findIt = find(line.rbegin(),line.rend(),' ');
    //The operator== used to determine the match between an element and the specified value must impose an equivalence relation between its operands.
    //In practice,if you want to use it with an object or a struct,you must overload the operator ==
    while(findIt != line.rend())
    {
        cout<.base(),tempIt.base());//[)
        //function base which convert reverse_iterator to iterator
        cout<<" ";
        tempIt = findIt + 1;
        findIt = find(findIt+1,line.rend(),' ');//[)
    }
    //We need to do special process to the first word
    cout<     cout<




阅读(1982) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~