Iterating through a vector and edit values via iterator by Dar1317th Jul 2010 14:30
|
---|
Summary Shows how to go through a vector and change the value of a vector using an iterator. Description First, we declare and initialize our vector(testVector), by pushing 3 values onto the back. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com #include <vector> #include <iterator> #include <iostream> int main() { std::vector<int> testVector; std::vector<int>::iterator itr; testVector.push_back(10); testVector.push_back(20); testVector.push_back(30); for(itr=testVector.begin(); itr!=testVector.end(); ++itr) { *itr+=1; std::cout<<*itr<<std::endl; } std::cin.get(); std::cin.get(); return 0; } |