2

Is it possible for me to set an ending istream_iterator other than the default constructed one?

One use case would be initializing a vector<int> with the first 13 elements from an istream_iterator<int>: vector<int>{ istream_iterator<int>(cin), x) where x is an iterator that is exactly 13 elements away from istream_iterator<int>(cin).

Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
  • 1
    Highly related: http://stackoverflow.com/questions/4086701/reading-a-partial-file-stream-into-a-string-using-iterators – NathanOliver Nov 04 '16 at 13:48
  • @NathanOliver It's crazy but I didn't even know that an `istreambuf_iterator` existed till that link made me look it up. The problem does seem to be the same though. This is do able with forward_iterators but not with just iterators. – Jonathan Mee Nov 04 '16 at 13:57
  • Well the problem is it is an input iterator which means when advanced it is read and can never go back. [Bart's answer](http://stackoverflow.com/a/4086867/4342498) Is how I would do this. – NathanOliver Nov 04 '16 at 13:58

0 Answers0