Advertisement
Guest User

main.cpp

a guest
Feb 21st, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include "employees.h"
  4.  
  5.  
  6. using std::cin, std::cout;
  7.  
  8.  
  9. int main() {
  10.     string com, file;
  11.     EmployeesArray arr;
  12.     while (true) {
  13.         cin >> com;
  14.         if (com == "add") {
  15.             cin >> arr;
  16.         }
  17.  
  18.         if (com == "list") {
  19.             cout << arr;
  20.         }
  21.  
  22.         if (com == "save") {
  23.             cin >> file;
  24.             std::ofstream Out;
  25.             Out.open(file, std::ios::out | std::ios::binary);
  26.             Out << arr;
  27.             Out.close();
  28.         }
  29.  
  30.         if (com == "load") {
  31.             cin >> file;
  32.             std::ifstream In;
  33.             In.open(file, std::ios::in | std::ios::binary);
  34.             if ((In.rdstate() & std::ifstream::failbit) != 0)
  35.                 std::cerr << "Error opening " << file << '\n';
  36.             In >> arr;
  37.             In.close();
  38.         }
  39.  
  40.         if (com == "exit") {
  41.             break;
  42.         }
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement