Advertisement
andruhovski

STL-map-demo

Feb 23rd, 2015
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. // SP-STL-02.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <map>
  8. using namespace std;
  9. class Student {
  10. public:
  11.     string FirstName;
  12.     string LastName;
  13. };
  14.  
  15. int _tmain(int argc, _TCHAR* argv[])
  16. {
  17.     Student s1,s2;
  18.     s1.FirstName="Ivan";
  19.     s1.LastName="Ivanov";
  20.     s2.FirstName="Petro";
  21.     s2.LastName="Petrov";
  22.  
  23.     map<int,Student> students_book;
  24.     map<int,Student>::iterator student;
  25.     students_book[124]=s1;
  26.     students_book[125]=s2;
  27.     /*cout << students_book[123].FirstName << " "<< students_book[123].LastName<<endl;
  28.     cout << students_book[124].FirstName << " "<< students_book[124].LastName<<endl;*/
  29.    
  30.     student = students_book.lower_bound(124);
  31.     if (student == students_book.end())
  32.         cout << "Not found" << endl;
  33.     else
  34.     {
  35.         cout << "Found " << student->first <<" "<<student->second.LastName << endl;
  36.     }
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement