Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9 KiB

  1. // See README.txt for information and build instructions.
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include "addressbook.pb.h"
  6. using namespace std;
  7. // Iterates though all people in the AddressBook and prints info about them.
  8. void ListPeople(const tutorial::AddressBook& address_book) {
  9. for (int i = 0; i < address_book.person_size(); i++) {
  10. const tutorial::Person& person = address_book.person(i);
  11. cout << "Person ID: " << person.id() << endl;
  12. cout << " Name: " << person.name() << endl;
  13. if (person.has_email()) {
  14. cout << " E-mail address: " << person.email() << endl;
  15. }
  16. for (int j = 0; j < person.phone_size(); j++) {
  17. const tutorial::Person::PhoneNumber& phone_number = person.phone(j);
  18. switch (phone_number.type()) {
  19. case tutorial::Person::MOBILE:
  20. cout << " Mobile phone #: ";
  21. break;
  22. case tutorial::Person::HOME:
  23. cout << " Home phone #: ";
  24. break;
  25. case tutorial::Person::WORK:
  26. cout << " Work phone #: ";
  27. break;
  28. }
  29. cout << phone_number.number() << endl;
  30. }
  31. }
  32. }
  33. // Main function: Reads the entire address book from a file and prints all
  34. // the information inside.
  35. int main(int argc, char* argv[]) {
  36. // Verify that the version of the library that we linked against is
  37. // compatible with the version of the headers we compiled against.
  38. GOOGLE_PROTOBUF_VERIFY_VERSION;
  39. if (argc != 2) {
  40. cerr << "Usage: " << argv[0] << " ADDRESS_BOOK_FILE" << endl;
  41. return -1;
  42. }
  43. tutorial::AddressBook address_book;
  44. {
  45. // Read the existing address book.
  46. fstream input(argv[1], ios::in | ios::binary);
  47. if (!address_book.ParseFromIstream(&input)) {
  48. cerr << "Failed to parse address book." << endl;
  49. return -1;
  50. }
  51. }
  52. ListPeople(address_book);
  53. // Optional: Delete all global objects allocated by libprotobuf.
  54. google::protobuf::ShutdownProtobufLibrary();
  55. return 0;
  56. }