Hi everyone,
I have a pair list stored in a vector; I try to enter in the first column of the list to count the number of lists stored for each element in the vector;
I try with this code;
1 2 3 4 5 6 7 8 9
for (std::vector<std::pair <uint32_t,uint32_t> >::iterator it = NeigborsNumber (GetDevice ()).begin(); it != NeigborsNumber (GetDevice ()).end (); it++)
{
typedef std::list <std::pair <uint32_t,uint32_t> > d_lista;
for (d_lista::iterator itt = it->begin(); itt != it->end(); itt++)
{
std::cout <<"{ "<<itt->first<<" }"<< std::endl;
}
}
I get this error:
1 2
error: struct std::pair<unsignedint, unsignedint>’ has no member named:end
error: struct std::pair<unsignedint, unsignedint>’ has no member named:begin
it->begin() What did you expect this to do? It is trying to call the function begin on the object the iterator is pointing at, which is a std::pair. What did you expect the non-existent function std::pair::begin() to do?
Each vector element is a single std::pair. You iterate over the vector, to get each pair in turn. You don't iterate over a pair - you just use the first and second members to access the data in a pair.
for (int i = 0; i < vector_of_pairs.size(); i++)
{
std::pair<unsignedint, unsignedint> current_pair = vector_of_pairs[i];
// now do something with current_pair
}