-4

I'm pretty new to programming and I'm wondering if there is a way in c++ to make a "while (there still are new values) {...}" By that I mean that, if you insert 6/50/400 values then press enter, it does the while operation 6/50/400 times, for each of the new values. Try to keep it simple if you can, I'm just a newcomer, and thanks in advance!

EDIT: Oh, right! Sorry guys, I didn't know there are books about C++. My bad! :D

  • no offense, but you are better off [reading a book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) instead of trying to learn C++ by asking questions here. – 463035818_is_not_an_ai May 05 '17 at 08:00
  • I agree, reading a book or some other good reference first will give you a better overview of C++, including flow control of course. – elnigno May 05 '17 at 08:09
  • If he's using spaces to separate the data, then `cin >> var` will not directly load all of them into the variable and he might indeed need a loop or another approach to handle it. –  May 05 '17 at 08:14

1 Answers1

0

The std::cin method from the iostream library returns true when it can read an input and false when it tries to read but there's nothing more to read. So you can use while(cin >> bar) and it will read input until it finds an EOF character (either from you pressing CTRL+D in the console or from reaching the end of a file redirected to stdin)

flapedriza
  • 342
  • 2
  • 12