Advertisement
Savonarolla

Untitled

Oct 30th, 2020
1,767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. void loadFile (vector <Phone*> &book, string path)
  2.     {
  3.         ifstream ifs;
  4.         ifs.open(path);
  5.  
  6.         if (!ifs.is_open())
  7.             {
  8.                 cerr << "Can't open the file " << endl;
  9.             }
  10.         else if (ifs.is_open())
  11.             {
  12.                 string newID, newFirstName, newLastName, newAddress, newPhoneNumber;
  13.                 char ch;
  14.                 book.clear();
  15.                 bool arr [5];
  16.                 while(ifs.get(ch))
  17.                     {
  18.                         if (ch != '\n' && !arr[0])
  19.                             {
  20.                                 newID += ch;
  21.                                 arr[0] = true;
  22.                             }
  23.                         while (ch != '\n' && !arr[1])
  24.                             {
  25.                                 newFirstName += ch;
  26.                                 arr[1] = true;
  27.                             }
  28.                         while (ch != '\n' && !arr[2])
  29.                             {
  30.                                 newLastName += ch;
  31.                                 arr[2] = true;
  32.                             }
  33.                         while (ch != '\n' && !arr[3])
  34.                             {
  35.                                 newAddress += ch;
  36.                                 arr[3] = true;
  37.                             }
  38.                         while (ch != '\n' && !arr[4])
  39.                             {
  40.                                 newPhoneNumber += ch;
  41.                                 arr[4] = true;
  42.                             }
  43.                     }
  44.                 Phone* newPhone = new Phone(newID,newFirstName, newLastName, newAddress, newPhoneNumber);
  45.                 book.push_back(newPhone);
  46.             }
  47.         ifs.close();
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement