【问题标题】:Adding a new entry into a list of maps?在地图列表中添加新条目?
【发布时间】:2016-03-14 04:22:05
【问题描述】:

如何在此电话簿程序中添加新条目?这就是我到目前为止所拥有的。任何提示或帮助都会很棒。

void enterNewEntry(std::map<std::string, std::list<PhoneEntry>*> & phoneInfo) {

    string  firstName;
    string  lastName;
    string  phoneNumStr;
    priority_t  priorityVal;

    enterFirstAndLastNames(firstName, lastName);
    enterPhoneNumStr(phoneNumStr);
    enterPriorityNum(priorityVal);
}

【问题讨论】:

    标签: c++ maps


    【解决方案1】:

    此代码 sn-p 不提供有关 PhoneEntry 类的信息,也不提供映射键, 但仍然:

    auto someList = new std::list<PhoneEntry>(); //creating empty list
    someList->insert(phoneEntryObject);          //fill list with data
    phoneInfo[someName] = someList;              //insert pair - key(someName) with mapped data(someList) into map container
    

    不要忘记手动释放内存,即使您只想擦除元素

    建议你看看 std::multimap STL 容器。

    【讨论】:

      猜你喜欢
      • 2011-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 1970-01-01
      • 2014-12-20
      • 2017-02-20
      相关资源
      最近更新 更多