mardi 2 novembre 2021

The value of iterator is not changing

I am trying to copy the values from a vector to an array but the value of the start iterator is not changing.

#include<iostream>
#include<vector>
using namespace std;
int main(){
   vector<int> vec(5,1);
   vector<int>::iterator start=vec.begin();
   int arr[vec.size()];
  for(int i=0;i!=vec.size();i++){
      arr[i]=*start;
      ++start;
  }
  for(auto i:arr){
      cout<<i;
  }
    return 0;
}

On debugging I found out that the initial value of start is 1 but as the loop runs it does not increment. I tried to increment it in another loop but it still won't change. I have no idea what I am doing wrong here.

Aucun commentaire:

Enregistrer un commentaire