Is there a more straight-forward way to do this?
for_each(v_Numbers.begin(), v_Numbers.end(), bind1st(operator<<, cout));
Without an explicit for loop, if possible.
EDIT:
How to do this for std::cin with a std::vector if possible? (How to read n elements only)?
You could achieve this using
std::copyinto astd::ostream_iterator:It would be even nicer if you add some suffix:
This assumes that your container is a
vector<int>, so you will have to replace that part with the appropriate type.Edit regarding reading input:
Conversely, you can copy from a range of
std::istream_iteratorinto avectorusingstd::back_inserter:If you want to read n elements only, look at this question.