vector value to another vector

closed account (yh54izwU)
I have been trying to figure out how to put the nameslist vector value that is randomly pulled and put it in pulled names thanks


string names[] ={"Tina","Aaron","Alan","Christi","Edgar","Marie","Sophia","Dale","Frank","Bruce","Marilyn","Joe","Alice","Natalia","Paul", "Katherine", "Simon", "Nick","Chris","Josh","Jeremy", "Nisa", "Marlon","Will","Eliza","Kat"};

vector<string> nameslist(names, names+25);
vector<string> pullednames(nameslong);

pullednames.insert(x,nameslist[pullme]); //this is what i tried

Thanks
vector<string> pullednames(nameslong); creates a vector which already has nameslong elements.
If you wrote no argument for the vector, you'd do pullednames.push_back(namelist[pullme]);.
Now you should do pullednames[x] = namelist[pullme]; and assure that x is never the same value (I assume x was an integer).
If you want to insert before xth element (which moves all other elements a bit to make space for a new one), write pullednames.insert(pullednames.begin()+x, namelist[pullme]);

By the way, notice that there is no reason to have nameslist vector. Using names array would work as well.
Topic archived. No new replies allowed.