Created
April 11, 2010 19:06
-
-
Save zachelko/362984 to your computer and use it in GitHub Desktop.
This file contains 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 <vector> | |
#include <iostream> | |
using namespace std; | |
int main() { | |
std::vector<int> foo; | |
// Add an item and then obtain an iterator to it | |
foo.push_back(3); | |
vector<int>::iterator current = foo.begin(); | |
// Check the addresses of our iterator and the first item | |
std::cerr | |
<< "Address of the current iterator: " << ¤t << std::endl; | |
std::cerr | |
<< "Address of our first object: " << &foo.at(0) << std::endl; | |
// Add a new item to the end and update our iterator | |
current = foo.insert(foo.end(),4); | |
std::cerr | |
<< "Address of the current iterator (same as before): " | |
<< ¤t << std::endl; | |
// Check the address of the first item | |
std::cerr | |
<< "Address of our first object different from before): " | |
<< &foo.at(0) << std::endl; | |
// See if our iterator is valid | |
std::cerr << "current (4): " << *current << std::endl; | |
return 0; | |
} | |
// output | |
// | |
// Address of the current iterator: | |
// 0xbf809f40 | |
// Address of our first object: | |
// 0x8ba1008 | |
// Address of the current iterator after adding a new item: | |
// 0xbf809f40 | |
// Address of our first object (different from before): | |
// 0x8ba1018 | |
// current (4): 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment