Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


8,120 questions

11,301 answers

573 users

How to insert value into vector at specific position in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

using std::cout;
using std::endl;
using std::vector;

int main()
{
	vector<int> vec = { 9, 1, 2, 3, 4, 1, 2, 3 };
	vector<int>::iterator it = vec.begin();

	it += 2;
	vec.insert(it, 1, 8008);

	for (it = vec.begin(); it != vec.end(); it++)
		cout << ' ' << *it;

	cout << endl;

	return 0;
}


/*
run:

9 1 8008 2 3 4 1 2 3

*/

 




answered May 17 by avibootz
edited May 17 by avibootz
...