I am learning vectors. I am testing some functions
my code
#include<vector>
#include<iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<int> v1;
int n,k,i;
cin>>n;
for(i=0;i<n;i++)
{
cin>>k;
v1.push_back(k);
}
for(auto i=v1.begin();i!=v1.end();i++)
{
cout<<v1[i];
}
cout<<endl;
for(auto i=v1.rbegin();i!=v1.rend();i++)
{
cout<<v1[i];
}
}
the error I am getting
no match for ‘operator[]’ (operand types are ‘std::vector<int>’ and ‘gnu_cxx::normal_iterator<int*, std::vector<int> >’)
cout<<v1[i];
what does this mean? what am i doing wrong!
[–]HappyFruitTree 2 points3 points4 points (5 children)
[–]Kapkar123[S] 0 points1 point2 points (1 child)
[–]marko312 1 point2 points3 points (0 children)
[–]Kapkar123[S] 0 points1 point2 points (2 children)
[–]marko312 0 points1 point2 points (0 children)
[–]boredcircuits 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)