Differentiating istream from ifstream parameter

The cin object is an instance of istream, but not ifstream. But istream cannot use the function open to read from files. That means if I want to make a general operator>> function that accepts an input and a place to store it, I have to check whether the istream object passed by the user is an ifstream or an istream. How do you check that?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
template <class FriendItemType>
istream& operator>>(istream & in, const object<FriendItemType>& storage);
{
	
	while(explicitly istream and in.good())
	{

           allocate memory in storage
           store input into storage
	}

	
	while(ifsteam and in.good())
	{

           allocate memory in storage
           store input into storage
	}	
}
Last edited on
You don't, because it doesn't.

The operator reads from (i)stream and that is it.
So the opening of a file is done on the client's part always?
Yes.
Topic archived. No new replies allowed.