How to print vector using ostream_iterator in C++

1 Answer

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

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

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

	std::ostream_iterator<int> output(cout, " ");

	std::copy(vec.begin(), vec.end(), output);

	cout << endl;

	return 0;
}

/*
run:

0 1 2 3 4 5

*/

 



answered Feb 26, 2018 by avibootz
edited Feb 27, 2018 by avibootz

Related questions

1 answer 244 views
1 answer 200 views
1 answer 247 views
1 answer 189 views
1 answer 181 views
181 views asked Dec 26, 2024 by avibootz
1 answer 269 views
...