mardi 10 septembre 2019

How to parse this vector through its 0th postition reference

I am trying to parse this simple array from the reference of its first element.

Here is my code:

#include <iostream>
#include <vector>
#include <algorithm>     

int main()
{
    vector<int> vec3 { 1,2,3,4,5};
    for( vector<int>::iterator ptr = &vec3[0]; ptr != vec3.end(); ++ptr )
    {
        cout << *ptr << " ";
    }
}

But I am getting this error:

[Error] conversion from '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type* {aka int*}' to non-scalar type 'std::vector<int>::iterator {aka __gnu_cxx::__normal_iterator<int*, std::vector<int> >}' requested

What's the problem?

Aucun commentaire:

Enregistrer un commentaire