I have looked to no avail, and I'm afraid that it might be such a simple question that nobody dares ask it.
Can one input multiple things from standard input in one line? I mean this:
float a, b;
char c;
// It is safe to assume a, b, c will be in float, float, char form?
cin >> a >> b >> c;
Yes, you can.
From cplusplus.com:
Just replace
strm
withcin
.Yes, you can input multiple items from
cin
, using exactly the syntax you describe. The result is essentially identical to:This is due to a technique called "operator chaining".
Each call to
operator>>(istream&, T)
(whereT
is some arbitrary type) returns a reference to its first argument. Socin >> a
returnscin
, which can be used as(cin>>a)>>b
and so forth.Note that each call to
operator>>(istream&, T)
first consumes all whitespace characters, then as many characters as is required to satisfy the input operation, up to (but not including) the first next whitespace character, invalid character, or EOF.