Source release 14.1.0
This commit is contained in:
23
third_party/protobuf/examples/list_people.cc
vendored
23
third_party/protobuf/examples/list_people.cc
vendored
@@ -1,24 +1,29 @@
|
||||
// See README.txt for information and build instructions.
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <google/protobuf/util/time_util.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "addressbook.pb.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
using google::protobuf::util::TimeUtil;
|
||||
|
||||
// Iterates though all people in the AddressBook and prints info about them.
|
||||
void ListPeople(const tutorial::AddressBook& address_book) {
|
||||
for (int i = 0; i < address_book.person_size(); i++) {
|
||||
const tutorial::Person& person = address_book.person(i);
|
||||
for (int i = 0; i < address_book.people_size(); i++) {
|
||||
const tutorial::Person& person = address_book.people(i);
|
||||
|
||||
cout << "Person ID: " << person.id() << endl;
|
||||
cout << " Name: " << person.name() << endl;
|
||||
if (person.has_email()) {
|
||||
if (person.email() != "") {
|
||||
cout << " E-mail address: " << person.email() << endl;
|
||||
}
|
||||
|
||||
for (int j = 0; j < person.phone_size(); j++) {
|
||||
const tutorial::Person::PhoneNumber& phone_number = person.phone(j);
|
||||
for (int j = 0; j < person.phones_size(); j++) {
|
||||
const tutorial::Person::PhoneNumber& phone_number = person.phones(j);
|
||||
|
||||
switch (phone_number.type()) {
|
||||
case tutorial::Person::MOBILE:
|
||||
@@ -30,9 +35,15 @@ void ListPeople(const tutorial::AddressBook& address_book) {
|
||||
case tutorial::Person::WORK:
|
||||
cout << " Work phone #: ";
|
||||
break;
|
||||
default:
|
||||
cout << " Unknown phone #: ";
|
||||
break;
|
||||
}
|
||||
cout << phone_number.number() << endl;
|
||||
}
|
||||
if (person.has_last_updated()) {
|
||||
cout << " Updated: " << TimeUtil::ToString(person.last_updated()) << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user