I have to read a file containing integers into a vector. I could do
something like this:
ifstream data("file.dat" );
istream_iterato r<intbegin(data );
istream_iterato r<intend;
vector<intc(beg in,end);
Now this does what i want it to.
But I read in Scott meyer's effective C++ that if I try to get rid of
the second and the thir statement and do something like this
ifstream data("file.dat" );
vector<intc(ist ream_iterator<i nt>(data), istream_iterato r<int>());
then this wouldn't work as expected because here the second line is
treated as a function declaration where c is the function which returns
a vector<intand takes two parameters: a)istream_itera tor<intb) a
function pointer which doesnt take any arguments and return a
istream_iterato r<int>
And that is the reason why this won't work.
But a friend of mine pointed me to this paper.
http://www.open-std.org/jtc1/sc22/wg...005/n1798.html
where it says that such a declaration won't work, not because it is
considered as a function declaration but because an istream_iterato r in
this case is considered as a forward iterator and that the
implementation of the constructor for vector which takes a forward
iterator is such that it is not possible to use an istream iterator
with them. I would request you to read the paper and correct me if I
misunderstood what the author said and let me know which one is right.