当前位置: 首页>>代码示例>>C++>>正文


C++ Person::add_phone方法代码示例

本文整理汇总了C++中Person::add_phone方法的典型用法代码示例。如果您正苦于以下问题:C++ Person::add_phone方法的具体用法?C++ Person::add_phone怎么用?C++ Person::add_phone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Person的用法示例。


在下文中一共展示了Person::add_phone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(true);
  Person p;
  p.set_email("[email protected]");
  p.set_id(123);
  p.set_name("abc");
  p.set_ismale(true);
  Person_PhoneNumber * phone = p.add_phone();
  phone->set_number("12345678911\"abc");
  phone->set_type(Person_PhoneType_HOME);
  phone->add_sn(1.2);
  phone->add_sn(1.3);
  phone->add_sn(1.4);

  phone = p.add_phone();
  phone->set_number("111111111111");
  phone->set_type(Person_PhoneType_WORK);
  phone->add_sn(2);
  phone->add_sn(3);
  phone->add_sn(4);
  // xml
  Person other;
  string result;
  string pretty;
  xproto::XmlMessageCodec codec;
  codec.ToString(p, result);
  cout << result << endl;
  cout << "--------123-------------------" << endl;
  codec.PrettyString(result, pretty);
  cout << pretty << endl;
  cout << "------------------------------" << endl;
  Person xmlPerson;
  codec.FromString(result, xmlPerson);
  codec.ToString(xmlPerson, result);
  cout << result << endl;
  codec.PrettyString(result, pretty);
  cout << pretty << endl;
  cout << "----------XmlObjectReader-----" << endl;
  xproto::XmlObjectReader Reader("data.xml");
  string xmlObj;
  while (Reader.Read(xmlObj)) {
    cout << xmlObj << endl;
    codec.CompactAndCheckString(xmlObj, result);
    cout << result << endl;
    codec.FromString(xmlObj, xmlPerson);
    codec.ToString(xmlPerson, result);
    codec.PrettyString(result, pretty);
    cout << pretty << endl ;
  }
  return 0;
}
开发者ID:cangyingzhijia,项目名称:xproto,代码行数:51,代码来源:xml-message-codec_test.cpp

示例2: 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);
    }
}
开发者ID:skhal,项目名称:Cpp,代码行数:64,代码来源:write.cpp

示例3: b


//.........这里部分代码省略.........
        //0x03abc4,defgzzz
        string data = "abc";
        string d2 = "defg";
        string tail = "zzz";
        int length = data.size();
        char buf[128];
        char *p = buf;
        memcpy(p, &length, sizeof(int));
        p += sizeof(int);
        strcpy(p, data.c_str());
        p += data.size();
        p += sprintf(p, "%d,", (int)d2.size());
        strcpy(p, d2.c_str());
        p += d2.size();
        strcpy(p, tail.c_str());
        p += tail.size();

        r.m_body = string(buf, p - buf);
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        if (! res)
        {
            EXPECT_EQ(0, 1);
            return ;
        }

        AddressBook ab;
        {
            Person* p = ab.add_person();
            p->set_name("zhangsan");
            p->set_id(3);
            p->set_email("[email protected]");
            Person::PhoneNumber* pp = p->add_phone();
            pp->set_number("010-11");
            pp->set_type(Person_PhoneType_WORK);
            pp = p->add_phone();
            pp->set_number("123");
            pp->set_type(Person_PhoneType_MOBILE);
        }
        {
            Person* p = ab.add_person();
            p->set_name("lisi");
            p->set_id(4);
        }
        string e;
        ab.SerializeToString(&e);

        EXPECT_EQ("abcd"+e, resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        //0x03abc4,defgzzz
        string data = "abc";
        string d2 = "defgg";
        string tail = "zzz";
        int length = data.size();
        char buf[128];
        char *p = buf;
        memcpy(p, &length, sizeof(int));
        p += sizeof(int);
        strcpy(p, data.c_str());
        p += data.size();
        p += sprintf(p, "%d,", (int)d2.size());
        strcpy(p, d2.c_str());
开发者ID:hqin6,项目名称:imock,代码行数:67,代码来源:utest_fmt_dat.cpp


注:本文中的Person::add_phone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。