9 #include "addressbook.pb.h"
17 cout <<
"Enter person ID number: ";
21 cin.ignore(256,
'\n');
23 cout <<
"Enter name: ";
24 getline(cin, *person->mutable_name());
26 cout <<
"Enter email address (blank for none): ";
30 person->set_email(email);
34 cout <<
"Enter a phone number (or leave blank to finish): ";
41 tutorial::Person::PhoneNumber* phone_number = person->add_phones();
42 phone_number->set_number(
number);
44 cout <<
"Is this a mobile, home, or work phone? ";
47 if (
type ==
"mobile") {
48 phone_number->set_type(tutorial::Person::MOBILE);
49 }
else if (
type ==
"home") {
50 phone_number->set_type(tutorial::Person::HOME);
51 }
else if (
type ==
"work") {
52 phone_number->set_type(tutorial::Person::WORK);
54 cout <<
"Unknown phone type. Using default." << endl;
57 *person->mutable_last_updated() = TimeUtil::SecondsToTimestamp(time(
NULL));
63 int main(
int argc,
char* argv[]) {
69 cerr <<
"Usage: " << argv[0] <<
" ADDRESS_BOOK_FILE" << endl;
79 cout << argv[1] <<
": File not found. Creating a new file." << endl;
81 cerr <<
"Failed to parse address book." << endl;
93 cerr <<
"Failed to write address book." << endl;