I got a piece of code like this:
template<class Iter>
void printRange(Iter begin, Iter last) {
for (Iter i = begin; i != last; i++) {
std::cout << *i << ", ";
}
outstd::cout << *last << ", ";
}
My question is: how can i print out the last element, too, elegantly? Couting the last element individually after the loop does not seem to be a nice and correct solution, … Is there a better way? Note that i cannot use the <= operator or boost or any stl specific feature either.
You can output the separator conditionally:
For a more standard
[begin, end)half-open range: