コード例 #1
0
ファイル: ReadAddressBook.cpp プロジェクト: csgwma/Onepiece
// 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);

    cout << "Person ID: " << person.id() << endl;
    cout << "  Name: " << person.name() << endl;
    //if (person.has_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);

      switch (phone_number.type()) {
        case tutorial::Person::MOBILE:
          cout << "  Mobile phone #: ";
          break;
        case tutorial::Person::HOME:
          cout << "  Home phone #: ";
          break;
        case tutorial::Person::WORK:
          cout << "  Work phone #: ";
          break;
      }
      cout << phone_number.number() << endl;
    }
  }
}
コード例 #2
0
ファイル: main.cpp プロジェクト: abtree1/cppbase
void print_person(tutorial::AddressBook &address_book){
	//解析消息数据
	for (int i = 0; i < address_book.person_size(); i++){
		const tutorial::Person &person = address_book.person(i);
		cout << "Person Id: " << person.id() << endl;
		cout << "Person Name: " << person.name() << endl;
		if(person.has_email())
			cout << "Person Email: " << person.email() << endl;

		for (int j = 0; j < person.phone_size(); j++){
			const tutorial::Person::PhoneNumber &phone = person.phone(j);
			switch (phone.type())
			{
			case tutorial::Person_PhoneType_HOME:
				cout << "Home Phone: ";
				break;
			case tutorial::Person_PhoneType_MOBILE:
				cout << "MOBILE Phone: ";
				break;
			case tutorial::Person_PhoneType_WORK:
				cout << "Work Phone: ";
				break;
			}
			cout << phone.number() << endl;
		}
	}
}
コード例 #3
0
ファイル: pjconv_test.cpp プロジェクト: bin3/pjconv
void Check(const tutorial::AddressBook& ab) {
  ASSERT_EQ(2, ab.person_size()) << "ab: " << ab.Utf8DebugString();
  const tutorial::Person& person2 = ab.person(0);
  EXPECT_EQ("bin3", person2.name());
  ASSERT_EQ(2, person2.phone_size());
  EXPECT_EQ("10000", person2.phone(0).number());
  EXPECT_EQ("10001", person2.phone(1).number());
}
コード例 #4
0
ファイル: main.cpp プロジェクト: abtree1/cppbase
void insert_person(tutorial::AddressBook &address_book){
	//封装消息数据
	tutorial::Person *person = address_book.add_person();
	person->set_name("Zhang3");
	person->set_id(1);
	person->set_email("*****@*****.**");
	tutorial::Person_PhoneNumber* phone1 = person->add_phone();
	phone1->set_number("123");
	phone1->set_type(tutorial::Person_PhoneType_MOBILE);
	tutorial::Person_PhoneNumber* phone2 = person->add_phone();
	phone2->set_number("456");
	phone2->set_type(tutorial::Person_PhoneType_HOME);
}