Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,051 questions

40,769 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, 2018 by avibootz
edited May 17, 2018 by avibootz

Related questions

...