C++Guns – RoboBlog

28.03.2016

C++ Examples

Filed under: — Thomas @ 03:03

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

http://en.cppreference.com/w/cpp/container/map/begin

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress