I’m having a problem with the following code:
for(int j = 0; j < ensembleTemp.size(); j++)
{
ensemble[ensembleTemp[j]].clear();
ensemble[ensembleTemp[j]].insert(ensemble[j].begin(),
ensembleTemp.begin(), ensembleTemp.end());
}
ensembleTemp is a vector<int>
and ensemble is a vector<vector<int>>. I have the following,
error: vector insert iterator outside range.
What’s my mistake?
You’re using the wrong index for the first parameter of insert, it (presumably) should be
The first parameter to insert should be an iterator for the vector being inserted into.
In addition ensemble.size() must be greater than ensembleTemp[j] for all j.