Write a function that takes and returns an istream&. The function should read the stream until it hits end-of-file. The function should print what it reads to the standard output. Reset the stream so that it is valid before returning the stream.
std::istream& func(std::istream &is)
{
std::string buf;
while (is >> buf)
std::cout << buf << std::endl;
is.clear();
return is;
}
What causes the following while to terminate?
while (cin >> i) /* ... */
putting cin
in an error state cause to terminate. such as eofbit
, failbit
and badbit
.
Why didn’t we use in-class initializers in PersonInfo?
Cause we need a aggregate class here. so it should have no in-class initializers.
Why did we declare entry and nums as const auto &?
const
.