Rika_Z

game list

Aug 3rd, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <string>
  5. using namespace std;
  6. int main()
  7. {
  8.     vector<string> games;
  9.     vector<string>::iterator iterGames;
  10.     bool lever = true;
  11.     while (lever == true)
  12.     {
  13.         cout << "\t\t\tList of your likest games\n";
  14.         cout << "Enter 'enum' to enumeration\n";
  15.         cout << "Enter 'add' to add\n";
  16.         cout << "Enter 'delete' to delete\n";
  17.         cout << "Enter 'exit' to exit\n";
  18.         string entValue;
  19.         cin >> entValue;
  20.         if (entValue == "enum")
  21.         {
  22.             if (games.size() == 0)
  23.             {
  24.                 cout << "Your list is empty\n\n";//если массив пуст он должен вывести это
  25.             }
  26.  
  27.             cout << "Your games\n";
  28.             for (iterGames = games.begin(); iterGames != games.end(); ++iterGames)//если нет то
  29.             {                                                           //перебрать массив
  30.                 cout << *iterGames << endl;                             //но он всегда выводит что массив пуст
  31.             }                                                           //хотя там есть данные
  32.             cout << "\n\n";
  33.  
  34.         }
  35.         else if (entValue == "exit")
  36.         {
  37.             cout << "You exit from list of games\n";
  38.             lever = false;
  39.         }
  40.         else if (entValue == "add")
  41.         {
  42.             string gameName;
  43.             do
  44.             {
  45.                 cout << "Enter name of game('back' to exit)\n";
  46.                 cin >> gameName;
  47.                 games.push_back(gameName);
  48.                 /*for (iterGames = games.begin(); iterGames != games.end(); iterGames++)
  49.                 {
  50.                     cout << *iterGames << endl;
  51.                 }*/
  52.             } while (gameName != "back");
  53.         }
  54.         else if (entValue == "delete")
  55.         {
  56.             string gameDelete;
  57.             cout << "Enter name of game you need to delete\n";
  58.             cin >> gameDelete;
  59.             iterGames = find(games.begin(), games.end(), gameDelete);//присваиваю итератору значение данных
  60.             cout << *iterGames << endl;                             //массива совпадющее с введенным пользователем
  61.             for (int i = 0; i <= games.size(); ++i)             //перебираю весь массив чтобы найти индекс данных массива
  62.             {
  63.                 if (iterGames == games.begin() + i)
  64.                 {
  65.                     cout << "Game found end delete\n\n";
  66.                     games.erase(games.begin() + i);                 //удаляю данные массива
  67.                 }
  68.                 else
  69.                 {
  70.                     cout << "not find\n\n";
  71.                 }
  72.             }
  73.         }
  74.         else
  75.         {
  76.             cout << "Invalid key\n\n";
  77.         }
  78.     }
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment