Hi community lm trying to insert an element in a specific position then displace all elements in a vector<>. l found there's a method wich l cannot understand how to use it. The following valid arguments are:
1 2
vector<int> myVec;
myVec.Insert (int * __position, constint & __x); // how l use this method?
for *__position l tried to create a pointer wich points to the element position, wich l want to insert the new element. It didnt work. lm suspecting *__position is an array or iterable object. Thanks in advance.
The __notation is something internal to the compiler. If that's what IntelliSense or something like that is giving you, probably ignore it (although it isn't exactly wrong, just misleading because it's showing internal stuff that shouldn't usually be seen).
// inserting into a vector
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myvector (3,100);
std::vector<int>::iterator it;
it = myvector.begin();
it = myvector.insert ( it , 200 ); // this is the call you are referring to in your post
myvector.insert (it,2,300);
// "it" no longer valid, get a new one:
it = myvector.begin();
std::vector<int> anothervector (2,400);
myvector.insert (it+2,anothervector.begin(),anothervector.end());
int myarray [] = { 501,502,503 };
myvector.insert (myvector.begin(), myarray, myarray+3);
std::cout << "myvector contains:";
for (it=myvector.begin(); it<myvector.end(); it++)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}