一个简单的电话簿程序将联系人推回矢量
a simple phonebook program push back contacts into the vector
我正在编写C 中的简单电话簿程序不使用类。我有一个添加联系人的函数。我想知道为什么它不起作用!如果您能帮助我,它不会将联系人推回矢量,我将非常感谢。包括我的代码的平静。
vector<ContactInfo> add(vector<ContactInfo> contacts, ContactInfo ci){
if(!(isRepetativeContact(contacts, ci)))
contacts.push_back(ci);
return contacts;
}
这是" isrepetativecontact"函数:
bool isRepetativeContact(const vector<ContactInfo>& contacts, const ContactInfo& ci){
for(int i = 0 ; i < contacts.size() ; i++)
if((contacts.size() != 0) && (contacts[i] == ci))
return true;
return false;
}
,我将contactInfo结构的操作员超载:
bool operator==(const ContactInfo& ci) const {
return (firstName == ci.firstName && lastName == ci.lastName &&
phoneNumber == ci.phoneNumber && emailAddress == ci.emailAddress &&
id == ci.id );
}
似乎您正在使用std :: vector重新创建std :: set。尝试使用std :: Set
std::pair<iterator,bool> insert( const value_type& value );
插入的返回值是一对。布尔指示该值是否已经在集合中;(插入成功(。迭代器指向std :: set中的元素(如果值已经在集合中,则指向现有值(
您不能在集合中重复。
相关文章:
- Mongodb c++驱动程序:如何查询元素的数组
- C++,系统无法执行指定的程序
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- C++ Windows 驱动程序MSB3030无法复制该文件,因为它找不到
- 重载操作程序时出错>>用于类中的字符串 memebr
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 试图在visual studio上用C++创建一个桌面应用程序
- 模板元程序查找相似的连续类型名称
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 如何通过cpp程序运行shell脚本
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- IPC使用多个管道和分支进程来运行Python程序
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- 如何从电话簿程序中删除联系人
- Outlook MAPI in C++ 应用程序中:按姓名查找联系人
- 一个简单的电话簿程序将联系人推回矢量
- C++联系人处理程序与自己的动态模板向量类
- 如何使用 C++ 程序获取 Thunderbird 的联系人
- 如何在Symbian应用程序中检查有效的联系人ID