Wednesday, April 13, 2011

Why param needs two arguments in following case:

I am sort of confused by this:

 istream_iterator<string> ii(is);
 istream_iterator<string> eos; 
 vector<string> param (ii, eos);
From stackoverflow
  • begin and end iterators. Empty istream_iterator means end of the input.

  • One for start and one for end

    RANDOM DATA BEGIN ITERATOR USEFUL DATA END ITERATOR RANDOM DATA

    Without "eos", how would the vector know when it has reached the end?

  • The constructor for std::vector that takes iterators needs a range, i.e., two iterators that specify where the input range starts and ends (and by end that usually means an iterator one past the end of the range).

    Even though you can use input iterators differently, you still need to pass a range to std::vector.

0 comments:

Post a Comment