std::vector::rbegin倒序迭代器

begin()和end()是顺序迭代,rbegin()和rend()是倒序迭代。详http://www.cplusplus.com/reference/vector/vector/rbegin/。
下面是一个实例:

// vector::rbegin/rend
#include 
#include 

int main ()
{
  std::vector<int> myvector (5);  // 5 default-constructed ints

  int i=0;

  std::vector<int>::reverse_iterator rit = myvector.rbegin();
  for (; rit!= myvector.rend(); ++rit)
    *rit = ++i;

  std::cout << "myvector contains:";
  for (std::vector<int>::iterator it = myvector.begin(); it != myvector.end(); ++it)
    std::cout << ' ' << *it;
  std::cout << '\n';

  return 0;
}

Output:myvector contains: 5 4 3 2 1

你可能感兴趣的:(c++学习记录)