Created
July 9, 2014 08:39
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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