在向量中查找和删除值 [英] Find and delete value in a vector
本文介绍了在向量中查找和删除值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Catalog
{
// string StationTitle;
string StationLocation;
public:
string StationTitle;
Catalog()
{
StationTitle = "";
StationLocation = "";
}
Catalog(string Title, string Location)
{
StationTitle = Title;
StationLocation = Location
}
void SetTitle(string Title) { StationTitle = Title; }
void SetLocation(string Location) { StationLocation = Location; }
string GetTitle() { return StationTitle; }
string GetLocation() { return StationLocation; }
};
class StationList
{
vector<Catalog> List; //create the vector
vector<Catalog>::iterator Transit;
public:
void Fill();
void Remove();
void Show();
};
void StationList::Remove()
{
string ToDelete;
cout << "Enter title to delete: " << endl;
cin >> ToDelete;
for(Transit = List.begin() ; Transit !=List.end() ; Transit++)
{
if(Transit->StationTitle() == ToDelete)
{
List.erase(Transit); //line 145
return;
}
}
}
输入StationTitle,并让程序找到标题,如果找到,删除它。这是我到目前为止所得到的。
它给我一个编译错误:chief.cpp:145:error:没有匹配的调用'(std :: string)()'
I would like the user to enter in a StationTitle and for the program to locate the title and delete it if found. This is what I have come up with so far.
It is giving me a compile error: chief.cpp:145: error: no match for call to ‘(std::string) ()’
推荐答案
您的错误在这里:
if(Transit->StationTitle() == ToDelete)
:
if(Transit->StationTitle == ToDelete)
OR
if(Transit->GetTitle() == ToDelete)
这篇关于在向量中查找和删除值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文