C++有关逆序输出数组

img


我定义了这样一个数组,用reverse会报错,不改变数组定义的方式的情况下,怎么写rever里面的参数才能翻转数组

逆序输出数组

#include <iostream>
#include <algorithm>
#include <iterator>

using namespace std;

int main()
{
    int a[] = {1, 2, 3, 4, 5};
    copy(rbegin(a), rend(a), ostream_iterator<int>(cout, " "));
    return 0;
}

reverse(a, a+n);//n为数组中的元素个数