【发布时间】:2020-12-16 05:30:29
【问题描述】:
我有一个结构,其中数据定义为:
typedef struct contacts
{
string name; //{jhonathan , anderson , felicia}
string nickName; //{jhonny , andy , felic}
string phoneNumber; // {13453514 ,148039 , 328490}
string carrier; // {atandt , coolmobiles , atandt }
string address; // {1bcd , gfhs ,jhtd }
} contactDetails;
vector <contactDetails> proContactFile;
在这里我想对name进行二进制搜索。如果搜索到的名称可用,那么我想显示该名称的相关联系方式(nickname,phone number ,carrier ,address)。我该怎么做?
【问题讨论】:
-
为什么不使用关联容器,例如
std::map<std::string, contactDetails>?
标签: c++ vector struct binary-search