3

Reading through accelerated c++, they give an example I don't understand. It's a while loop with condition (cin>>x). At this point in the script, x has been declared as a double. I understand that the loop executes as long as x successfully receives input, but is >> returning a boolean? I guess I just need a little help understanding exactly what it is >> and << do.... Also while we're on the subject, whats the difference between iostream, ios and iomanip

hedgehogrider
  • 1,168
  • 2
  • 14
  • 22
  • 1
    You should break this into two questions. The first part, described in the question title is one question, but everything thing after 'Also while we're on the subject' is a different question and thus should be a different question. – SingleNegationElimination Nov 14 '10 at 07:02

1 Answers1

8

actually, they return themselves, that is,

std::cin >> foo

is an expression (with a side effect) that happens to return std::cin. It also happens that iostreams can be converted to bool, they are true if they are ready to recieve input, or have output to provide, and false if they are closed or at the end of their respective files.

SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
  • 1
    More precisely, they're converted to `void*`, which is then converted to `bool`. And a stream may also evaluate to `false` even when there *is* input available. If `foo` is an `int` and the next characters to extract aren't numeric, for example, then the stream will be in the `fail` state. Call `clear` to reset. – Rob Kennedy Nov 14 '10 at 07:21