Cannot figure out where I went wrong. As I understand, this code should return "1, 2, 3" but I get the following. I need the vector and its iterators declared globally because I am passing the vector to functions in my actual code and need to update the iterators as well in some functions. Any help is appreciated!
#include <iostream>
#include <vector>
using namespace std;
vector<float> grid;
vector<float>::iterator gridPtr;
int main()
{
  grid.push_back(1);
  grid.push_back(2);
  gridPtr = grid.begin();
  grid.push_back(3);
  cout << "gridPtr: " << *gridPtr << endl;
  gridPtr++;
  cout << "gridPtr: " << *gridPtr << endl;
  gridPtr++;
  cout << "gridPtr: " << *gridPtr << endl;
}
This returns:
gridPtr: 2.62257e-33
gridPtr: 2
gridPtr: 0
 
     
     
    