How to insert something in a list using its iterator? for example, I have a list of objects myobj
where myobj
contains another list<int>
.
class myobj {
//other data goes here
list<int> l;
};
list <myobj> x;
Suppose I want to call the insert()
function for the list in the nth element of x
, I'll do something like
list<myobj>::iterator itr = x.begin();
std::advance(itr,n);
itr->insert(n); //It gives a compilation error.
I tried to learn insert_iterator
but most of the examples I got were used with copy()
function but here I want to call the insert()
function of the list inside myobj
.