C++ Examples
Container
Map
#include <map> #include <string> #include <iostream> #include <iterator> int main() { std::map<std::string,std::string> a_map; a_map["Geely"] = "Chinese"; a_map["Peugeot"] = "French"; a_map["Mercedes"] = "German"; a_map["Toyota"] = "Japanese"; a_map["Ford"] = "American"; a_map["Fiat"] = "Italian"; // print the first 3 items for (auto it = std::cbegin(a_map); it != std::next(std::cbegin(a_map), 3); ++it) { std::cout << it->first << " : " << it->second << '\n'; } }
Output:
Fiat : Italian
Ford : American
Geely : Chinese