开发者

Is cin a proper file object?

开发者 https://www.devze.com 2022-12-22 16:06 出处:网络
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 istr

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

精彩评论

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

关注公众号