-4
如果元素不存在,返回false嗎?我試圖遍歷一個矢量,並且只要它們存在就打印出每個已排序的元素。這裏的代碼片段,我一起工作:向量C++排序和打印
typedef struct {
string Name;
map<string,string> Numbers;
} Person
bool ComparebyAlpha(const Person &person1, const Person &person2) {
return person1.Name < person2.Name;
}
voic print_Contacts(vector <Person> Contacts) {
sort(Contacts.begin(), Contacts.end(), ComparebyAlpha);
int num = 0;
while (Contacts[num]) {
cout << Contacts[num].Name;
num++;
}
}