pmcgee

map test classic compiler

Jun 19th, 2020
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #pragma hdrstop
  2. #pragma argsused
  3.  
  4. #include <string>
  5. #include <iostream>
  6. #include <iterator>
  7. #include <map>
  8.  
  9. using namespace std;
  10.  
  11. struct TTest   {
  12.     string  ID;
  13.     string  Name;
  14.     string  Show()  {  return  ID + " - " + Name;   }
  15. };
  16.  
  17.  
  18. typedef map<string,TTest> TTestMapList;
  19.  
  20. TTestMapList& GetTestList()   {
  21.     static TTestMapList TestList;
  22.     return TestList;
  23. }
  24.  
  25.  
  26. bool GetTest(string str, TTest& T) {
  27.     TTestMapList::iterator it = GetTestList().find(str);
  28.     bool res = (it != GetTestList().end());
  29.     if (res)  T = it->second;
  30.     return res;
  31. }
  32.  
  33.  
  34. int main()  {
  35.     TTest s, t ;
  36.     t.ID   = "1";
  37.     t.Name = "abc";
  38.  
  39.     GetTestList().insert( pair<string, TTest> ("5", t) );
  40.  
  41.     if (GetTest("5", s))  {
  42.          s.ID   = "1985";
  43.          s.Name = "Ahmed Mido Sayed";
  44.     }
  45.  
  46.     cout << t.Show() << "\n";
  47.     cout << s.Show() << "\n";
  48.  
  49.     int x; cin >> x;
  50.  
  51. }
Add Comment
Please, Sign In to add comment