How to print vector contain ints with ostream_iterator in C++

1 Answer

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

int main()
{
	std::vector<int> vec;

	for (int i = 1;  i <= 5; i++) 
		 vec.push_back(i);

	std::ostream_iterator<int> output(std::cout, " ");
	
	std::copy(vec.begin(), vec.end(), output);

	std::cout << std::endl;

	return 0;
}

/*
run:

1 2 3 4 5

*/

 



answered Jan 3, 2018 by avibootz

Related questions

1 answer 195 views
1 answer 124 views
1 answer 171 views
1 answer 178 views
1 answer 117 views
1 answer 184 views
...