[C++]vector 的逆向迭代器

有了逆向迭代器,反转就方便多了

        vector<int> a = {1,2,3,4,5};
    vector<int> c;
    c.insert(c.end(),a.rbegin(),a.rend());
    cout<<c[0]<<c[1]<<c[2]<<c[3]<<c[4]<<endl;

输出:

54321

这里如果把最后一个a.rend()换成a.begin()是不行的,同理a.rbegin()也不能换成a,end();

猜你喜欢

转载自www.cnblogs.com/drunknbeard/p/10256961.html