Advertisement
Guest User

kvdb.cxx

a guest
Jun 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.04 KB | None | 0 0
  1. "#include <iostream>
  2. #include <map>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     map<string, string> db;
  10.     cout << "Welcome to the simplest key-value database" << endl;
  11.     while (1)
  12.     {
  13.         cout << "What do you want to do?" << endl;
  14.         cout << "Enter P to [P]ut, G to [G]et or L to [L]ist" << endl;
  15.         cout << "Or enter Q to [Q]uit" << endl;
  16.         string action;
  17.         getline(cin, action);
  18.         if (action == "P")
  19.         {
  20.             string key;
  21.             string data;
  22.             cout << "Enter key: ";
  23.             getline(cin, key);
  24.             cout << "Enter data: ";
  25.             getline(cin, data);
  26.             db[key] = data;
  27.         }
  28.         if (action == "G")
  29.         {
  30.             cout << "Enter key: ";
  31.             string key;
  32.             getline(cin, key);
  33.             if (db.find(key) != db.end())
  34.             {
  35.                 cout << "Your data: " << db[key] << endl;
  36.             }
  37.             else
  38.                 cout << "No such key" << endl;
  39.         }
  40.         if (action == "L")
  41.         {
  42.             cout << "DB contents:" << endl;
  43.             for (auto it = db.begin(); it != db.end(); it++)
  44.             {
  45.                 cout << it->first << ": " << it->second << endl;
  46.             }
  47.         }
  48.         if (action == "Q")
  49.         {
  50.             cout << "Bye" << endl;
  51.             break;
  52.         }
  53.         cout << endl;
  54.     }
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement