Istream help

Need help with understanding the real uses of istream, ostream, and ifstream. Outside of using files I only know to actually call it in files ,but why would you need to call it inside of a regular function like so.
 
bool user::thedate(istream &b)

I typed that because I was just expermienting with it and I just don't understand the real uses for something like this. Please elaborate on why some people use istream instead of calling it a int or string.
Also I know the meaning of them:
ostream means output stream.
istream means input stream .
ifstream is both.
Might be wrong because if I knew for sure I wouldn't be asking this question
I use ifstream to input files. I use ofstream for output to files. that's about all I know.
ostream is an output stream.
istream in an input stream.
ifstream is an input file stream.
ofstream in an output file stream.
fstream is a (both input/output) file stream.

A trivial example of when you may want to use a stream:
Suppose you wanted to write a function called "write()" that would write a string to a file. Now, obviously you can just do this with operator>>, but let's try anyway. You'll need to take two arguments; the file to write to and the string to write. You could pass just a filename and have the function open the stream itself, but what if the calling code wants to write to stand output (std::cin) instead? You can't handle that without letting the calling code pass an arbitrary stream. So you might write the following:
1
2
3
void write(std::ostream& out, const std::string& writeMe) {
    out << writeMe;
}
Topic archived. No new replies allowed.