本文整理汇总了C++中AddressBook::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ AddressBook::push_back方法的具体用法?C++ AddressBook::push_back怎么用?C++ AddressBook::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AddressBook
的用法示例。
在下文中一共展示了AddressBook::push_back方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: promptForAddress
void promptForAddress(AddressBook &book)
{
while(true)
{
cout << "Enter person ID number [0 to quit]: ";
Person person;
{
int id;
cin >> id;
if (!id)
break;
person.setId(id);
cin.ignore(256, '\n');
}
{
cout << "Enter name: ";
std::string name;
getline(cin, name);
person.setName(name);
}
{
cout << "Enter email address (blank for none): ";
string email;
getline(cin, email);
if (!email.empty())
person.setEmail(email);
}
while(true)
{
cout << "Enter a phone number [Enter to finish]: ";
string number;
getline(cin, number);
if (number.empty())
break;
Phone *phone = person.add_phone();
phone->setNumber(number);
cout << "Is this a mobile, home or work phone? ";
string type;
getline(cin, type);
if ("mobile" == type)
phone->setType(Phone::MOBILE);
else if ("home" == type)
phone->setType(Phone::HOME);
else if ("work" == type)
phone->setType(Phone::WORK);
else
cout << "Unknown phone type. Using default." << endl;
}
book.push_back(person);
}
}