0

In this code.

vector<int> iVect{std::istream_iterator<int>(cin),std::istream_iterator()}; 

why do I have to use the uniform initialization syntax, instead of using the regular syntax?

BoBTFish
  • 19,167
  • 3
  • 49
  • 76
Maths
  • 11
  • 1
  • 1
    First, you are missing `` from the second iterator constructor, and secondly, why do you think you do? You should ask about and show us the code that *doesn't* work (rather than asking about code you haven't shown us), and make sure you include the full error message. – BoBTFish Apr 12 '17 at 08:41
  • Isn't your second std::istream_iterator() missing a template argument? What is the context of this code, where do you place it? – Martin Hierholzer Apr 12 '17 at 08:42
  • 1
    Because otherwise it declares a function. Search for "most vexing parse". – molbdnilo Apr 12 '17 at 08:48
  • #include #include #include #include using namespace std; int main() { vector iVect(istream_iterator(cin),istream_iterator()); copy(begin(iVect),end(iVect),ostream_iterator(cout, " ")); } this is my original code. The error I get is the following tmp.cpp: In function ‘int main()’: tmp.cpp:9:18: error: no matching function for call to ‘begin(std::vector (&)(std::istream_iterator, std::istream_iterator (*)()))’ copy(begin(iVect),end(iVect),ostream_iterator(cout, " ")); – Maths Apr 12 '17 at 08:49
  • @Maths Please add your code to the question, not in the comments. – molbdnilo Apr 12 '17 at 08:49

0 Answers0