void FileIO::read(PhoneBook & pb) { ifstream fin("a.txt"); string buf; int count; vector<string> fields; fin >> count; fin.get(); for (int i=0; i<count; ++i) { getline(fin, buf); fields.push_back(buf); } pb.setFields(fields); fin >> count;fin.get(); Record newrec(pb); for (int i=0; i<count; ++i) { fin >> newrec; fin.get(); pb.addRecord(newrec); } fin.close(); }
void CmdInterface::onAddRecord(PhoneBook & pb) { Record newrec(""); string tmp; println("Input the person's name:"); newrec.setName(getLine()); println("Input the phone number:"); newrec.setPhone(getLine()); println("Input the address:"); newrec.setAddr(getLine()); pb.addRecord(newrec); println("Record successfully added."); }
void CmdInterface::addRecord(PhoneBook & pb) { Record newrec(""); string tmp; cin.ignore(); cout << "Input the person's name:" << endl; newrec.setName((getline(cin, tmp), tmp)); cout << "Input the phone number:" << endl; newrec.setPhone((getline(cin, tmp), tmp)); cout << "Input the address:" << endl; newrec.setAddr((getline(cin, tmp), tmp)); pb.addRecord(newrec); cout <<"Record successfully added.\n"; }