Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void loadFile (vector <Phone*> &book, string path)
- {
- ifstream ifs;
- ifs.open(path);
- if (!ifs.is_open())
- {
- cerr << "Can't open the file " << endl;
- }
- else if (ifs.is_open())
- {
- string newID, newFirstName, newLastName, newAddress, newPhoneNumber;
- char ch;
- book.clear();
- bool arr [5];
- while(ifs.get(ch))
- {
- if (ch != '\n' && !arr[0])
- {
- newID += ch;
- arr[0] = true;
- }
- while (ch != '\n' && !arr[1])
- {
- newFirstName += ch;
- arr[1] = true;
- }
- while (ch != '\n' && !arr[2])
- {
- newLastName += ch;
- arr[2] = true;
- }
- while (ch != '\n' && !arr[3])
- {
- newAddress += ch;
- arr[3] = true;
- }
- while (ch != '\n' && !arr[4])
- {
- newPhoneNumber += ch;
- arr[4] = true;
- }
- }
- Phone* newPhone = new Phone(newID,newFirstName, newLastName, newAddress, newPhoneNumber);
- book.push_back(newPhone);
- }
- ifs.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement