我有一個std :: map,我使用迭代器來查找某個鍵,值對。找到它後,我無法從迭代器中獲取鍵值對的位置。通過做另一個發現我可以得到它,但我想爲此工作。迭代器操作問題
//mycode is this
std::map<std::string,myclass*> mymap;
size_t myfind(const std::string &s)
{
std::map<std:string,myclass*>::iterator i=mymap.find(s);
if((i==mymap.end())||((*i).second==0))
{
std::cout<<"some error\n";
}
else
{
//here i need to return the size_t value of the iterator i
}
}
注:編輯爲size_t關鍵的位置,值對
你是什麼意思「來自迭代器的size_t值」? size_t是C中的一個類型,它不是迭代器的值。請詳細說明 – 2010-03-04 04:53:48
迭代器的「size_t」值是什麼意思? – Naveen 2010-03-04 04:54:25
什麼'size_t'值?您的地圖使用'std :: string'作爲鍵,'myclass *'作爲值。我沒有在任何地方看到任何'size_t' ... – 2010-03-04 04:54:42