开发者

Is cin a proper file object?

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&.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜