As in, can I pass cin to any function that accepts an ifstream object?
views:
113answers:
2
+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
2010-03-13 03:45:37
Though I believe calls trying to seek or get the length of the stream will fail, though not 100% sure on this.
Grant Peters
2010-03-13 05:00:17
+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
2010-03-13 03:57:59