How to create and initialize vector in C++

1 Answer

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

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

int main() 
{
	std::vector<int> vec = { 1, 2, 3, 4, 5 };

	for (int i : vec)
		cout << i << " ";
	
	cout << endl;

	return 0;
}

/*
run:

1 2 3 4 5

*/

 



answered Feb 15, 2018 by avibootz

Related questions

2 answers 175 views
1 answer 103 views
1 answer 182 views
1 answer 104 views
1 answer 121 views
...