tags:

views:

113

answers:

2

As in, can I pass cin to any function that accepts an ifstream object?

+10  A: 

std::cin is not a file stream, but an input stream, or istream. You can pass it to any function that accepts an istream.

Shakedown
Though I believe calls trying to seek or get the length of the stream will fail, though not 100% sure on this.
Grant Peters
+4  A: 

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

Potatoswatter