// C++ program to illustrate the begin and end iterator #include #include #include using namespace std; int main() { // Create a map of strings to integers map mapObject ; // Insert some values into the map mapObject["one"] = 1 ; mapObject["two"] = 2 ; mapObject["three"] = 3 ; // Get an iterator pointing to the first element in the // map map::iterator it = mapObject.begin() ; // Iterate through the map and print the elements while ( it != mapObject.end() ) { cout << "Key: " << it->first << ", Value: " << it->second << endl; ++it; } cout << "Range loop to access map objects." << endl ; //Range loop for( pair p1 : mapObject ) { cout << "Key: " << p1.first << ", Value: " << p1.second << endl; } //for return 0; }