vector<int>v1{ 54,54,546,65,5,5454,35,7 }; vector<int>v3{}; for (auto it : v1) //ни так v3.insert(it); for (auto i = v1.begin(); i != v1.end(); ++i) //ни так v3.insert(*i); 2 answers
First, insert for a vector requires two parameters - where to insert, and what to insert. You transmit just now .
Secondly, do not use insert with a vector at all - except in the most extreme cases ... limit push_back() .
And in general, in your particular case, a simple assignment is sufficient -
v3 = v1; If you really want to insert - then it's better
v3.insert(v3.end(),v1.begin(),v1.end()); |
The insert method requires you to specify where to insert the item. If you need to add to the end:
vector<int>v1{ 54,54,546,65,5,5454,35,7 }; vector<int>v3{}; for (auto it : v1) v3.push_back(it); for (auto i = v1.begin(); i != v1.end(); ++i) v3.push_back(*i); for (auto it : v1) v3.insert(v3.end(), it); |