I am new to c++ and am trying to assign two variables within a vector, one being at the first index and the other at the (first index + 1).
Here is what I have so far:
#include <iostream>
#include <iterator>
#include <vector>
using std::cout, std::endl, std::vector;
int main() {
vector<int> numList{25, 10, 4, 3, 1, 6};
int var1;
int var2;
// Looping through vector
for(auto it = numList.begin(); it != numList.end(); ++it) {
int index = std::distance(numList.begin(), it);
var1 = numList[index];
var2 = numList[index + 1];
}
cout << "var1: " << var1 << " var2: " << var2 << endl;
}
I am expecting this to print out: var1: 25 var2: 10
The actual output is: var1: 6 var2: 0