我寫了一個程序來查找重複的2D矢量C++。我只檢查了一個字段,即名稱字段。這是限制重複輸入的有效方法嗎?要在2D向量中找到重複向量C++
typedef vector<vector<string>> table_t;
table_t myvec = {{"DINU","56","66","45","78","76"},
{"HARI","56","78","54","85","62"},
{"JAMES","65","34","54","64","98"},
{"HEARTLY","76","76","87","34","76"},
{"PETER","67","78","87","34","53"}};
int main(int argc, char *argv[])
{
if(argc!=7)
{
cout<<"Enter 7 Fields"<<endl;
exit(0);
}
string name = argv[1];
upperto(name);
for(size_t i=0;i<myvec.size();i++)
{
if(name == myvec[i][0])
{
id++;
}
}
if(id==0)
{
myvec.push_back({name,argv[2],argv[3],argv[4],argv[5],argv[6]});
}
else
{
cout<<'\n'<<"Already Exist"<<endl;
}
}
你知道'的std ::向量<>'本來['運營商=='](HTTP://en.cppreference。 com/w/cpp/container/vector/operator_cmp),對吧? – WhozCraig
爲什麼沒有std :: map>? –
我想限制使用特定記錄的重複。我不希望整個記錄限制重複。 – user3475204