I am writing a program that implements a uni-directional graph using std::map. I have to search for the key and then copy the vector values corresponding to that key into a new location in the map. The problem is that the key I search for is extracted from yet another location in the map. I understand why I am getting the error as std::copy_n does not copy from vector to string (although it works the other way) but I don't know how to fix this. I am copying a snippet of the code below: The keys to search for are stored in a vector corresponding to key mykey.
for (
vector<string>::iterator itr = mymap.find(mykey)->second.begin()
; itr != mymap.find(mykey)->second.end()
; itr++
)
{
string find_key = "";
// error C2664 :cannot convert parameter 1 from 'std::_Vector_iterator<_Myvec>'
// to 'const std::basic_string<_Elem,_Traits,_Ax> &'
std::copy_n(itr, 1, find_key.begin());
if (mymap.find(find_key) == mymap.end())
cout << "key not found" << endl;
else
mymap[mykey].insert(
mymap.find(find_key)->second.begin()
, mymap.find(find_key)->second.end()
);
}
Aucun commentaire:
Enregistrer un commentaire