c++ 顺序容器 逆序输出

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int a[11] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    vector<int> vec(a, a+11);
    //方法1
    for (vector<int>::iterator it = vec.end(); it != vec.begin();)
    {
        cout << *(--it) << " ";
    }
    cout << "\n";
    //方法2
    for (vector<int>::reverse_iterator it = vec.rbegin(); it != vec.rend(); ++it)
    {
        cout << *it << " ";
    }
    system("pause");
}
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐