Skip to content

Instantly share code, notes, and snippets.

@FlyingJester
Created July 9, 2014 08:39
Show Gist options
  • Select an option

  • Save FlyingJester/41ab49e34417657ecce5 to your computer and use it in GitHub Desktop.

Select an option

Save FlyingJester/41ab49e34417657ecce5 to your computer and use it in GitHub Desktop.
Example of how to use a normal iterator to iterate backward through a vector.
#include <iostream>
#include <map>
#include <vector>
int main()
{
std::vector<int> noobles;
for(int i = 0; i<10; i++)
noobles.push_back(i+1);
std::map<std::string, int> lolMap;
lolMap["noob"] = 1;
lolMap["lol"] = 100;
for(std::vector<int>::iterator i = noobles.end()-2;
i!=noobles.begin()-2; i--){
std::cout << *i << "\n";
if((*i)%2==0)
noobles.erase(i);
}
std::cout << "Printing odds only.\n";
for(std::vector<int>::iterator i = noobles.end()-2;
i!=noobles.begin()-2; i--){
std::cout << *i << "\n";
}
std::cout << "Hello World" << lolMap["lol"] << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment