As others have mentioned in the comments, you should not be using insert
in this case, you should be using push_back
vectorB.push_back(*it);
You would typically use insert
if there is a specific position that you want to insert the new element. If you are not interested in adding the element to a specific position, then you can use push_back
to (as the name suggests) add the element to the end of the vector.
solved Fail to insert the element of the set to the vector in c++