0

I have the following two lines of code:

vector<int> temp(istream_iterator<int>(cin), 
                 istream_iterator<int>());

copy(temp.begin(), temp.end(), ostream_iterator<int>(cout, " "));

Which is supposed to read from stdin into a vector containing int and prints it to stdout.

But I get the following error:

request for member ‘begin’ in ‘temp’, which is of non-class type ‘std::vector<int>(std::istream_iterator<int>, std::istream_iterator<int> (*)())’
 copy(temp.begin(), temp.end(), ostream_iterator<int>(cout, " "));

Which I suspect I get is because the vector initialization looks suspiciously like a function prototype. How do I fix this?

user3666471
  • 907
  • 11
  • 24
  • It's not saying function call, it's saying function declaration. – chris Jul 19 '16 at 03:13
  • 1
    `istream_iterator(cin)` ===> `(istream_iterator(cin))`, or just use universal initialization. [See this question](https://stackoverflow.com/questions/28094774/most-vexing-parse-c11) for examples of both techniques. – WhozCraig Jul 19 '16 at 03:16
  • More on most vexing parse: http://stackoverflow.com/questions/1424510/most-vexing-parse-why-doesnt-a-a-work – bitcode Jul 19 '16 at 03:22
  • Use `vector temp(istream_iterator{cin}, istream_iterator{});`. – R Sahu Jul 19 '16 at 03:29

0 Answers0