Advertisement
andruhovski

map_demo_2014

Feb 11th, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. // ConsoleApplication4.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <map>
  6. #include <string>
  7. #include <iostream>
  8. #include <iterator>
  9.  
  10. using namespace std;
  11.  
  12. int _tmain(int argc, _TCHAR* argv[])
  13. {
  14.     map <int, string> my_students_list; //value_type
  15.     int stud_num=1234;
  16.     string stud_name="Petrenko";
  17.     my_students_list.insert(make_pair(stud_num,stud_name));
  18.     my_students_list.insert(map<int, string>::value_type(2345,"Antonov"));
  19.     cout << my_students_list[1234] << endl;
  20.    
  21.     if (my_students_list.find(123)!=my_students_list.end())
  22.         cout << my_students_list[123] << endl;
  23.     else
  24.         cout << "Student not found" <<  endl;
  25.    
  26.     auto ret = my_students_list.insert(map<int, string>::value_type(234,"Bogach"));
  27.     if (!ret.second){
  28.         cout << "Element already exists." << endl;
  29.     }
  30.     else{
  31.         cout << "Element inserted:" << endl;
  32.         cout << my_students_list[234] << endl;
  33.     }
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement