How to print vector using InIter in C++

1 Answer

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

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

template<class InIter>
void print(InIter start, InIter end) {

	InIter intit;

	for (InIter intit = start; intit != end; intit++)
		cout << *intit << " ";

	cout << endl;
}

int main()
{
	vector<int> vec = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	
	print(vec.begin(), vec.end());

	return 0;
}

/*
run:

0 1 2 3 4 5 6 7 8 9

*/

 



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

Related questions

1 answer 157 views
1 answer 102 views
102 views asked Dec 26, 2024 by avibootz
1 answer 169 views
2 answers 231 views
231 views asked Apr 24, 2018 by avibootz
1 answer 197 views
1 answer 94 views
1 answer 117 views
...