initialising a vector from iterators

Hey,
I m trying to tokenize a string into its words and found a code example on stackoverflow that puts the string into a stringstream and uses a istream iterator to initialize a vector containing the words. the link: http://stackoverflow.com/questions/53849/how-do-i-tokenize-a-string-in-c
its the 3rd answer. it gets the words into a vector which is what i have to do anyways and i understand the basic principles. i wrote a little funtion looking like this:
1
2
3
4
5
6
7
8
9
10
11
#include "storeInput.h"

vector<string> storeInput(string input)
{
  stringstream strStream(input)
  istream_iterator<string> strStreamIterator(strStream)
  istream_iterator<string> end;

  vector<string> result(strStreamIterator, end);
  return result;
}


The part i am not 100% clear on is the use of the iterator end. can someone explain how that works?
Any range is defined by a pair of iterators, begin and past-the-end.

With containers, the past-the-end iterator is provided by the container with the .end()/.cend() member function.

With single-pass input iterators, such as istream_iterator, there is no way to obtain the past-the-end iterator without actually doing the entire pass, and once you do that, you cannot go back (imagine reading a TCP socket)

So instead, every default-constructed istream_iterator serves as the past-the-end iterator for every istream_iterator range (of the same type).
Topic archived. No new replies allowed.