As in,开发者_如何学Go can I pass cin
to any function that accepts an ifstream object?
std::cin
is not a file stream, but an input stream, or istream
. You can pass it to any function that accepts an istream.
std::cin
is a std::istream
.
There is little difference between class istream
and its derivative ifstream
. ifstream
allows you to open and close files, providing open()
, close()
, and is_open()
, and a constructor which calls open()
— and that's it!
If your function doesn't use those methods, it should take an istream&
instead of an ifstream&
.
精彩评论