I have a method that needs to pass in an istream as a parameter:
istream has three subsets, correct? iostream, ifstream, istringstream
int readRouteData(istream & inSource);
Now i'm not clear on exactly what an istream is - "istream objects are stream objects used to read and interpret input from sequences of characters" - or how I would go about using one. Aren't cin/cout part of iostream? What is the point of passing in an istream to a method instead of retrieving the data beforehand and passing in the string instead? How would I go about declaring an istream variable?
You don't (necessarily) pass an istream to the function, you pass cin, or an ifstream, or an istringstream. The function takes an istream& as its parameter so that you can pass any of the three and it will work the same.
The point of having it do that is so you can read in your data from a stream (likely in a text format) the same way whether you are reading from cin or from a file or from a string.
If you only ever read in your data from cin, then you can still leave it as istream. Same if you only ever want to read from a file right now. The point is flexibility.
So when I called the function it might look like this?
Usually I have data either coming from the keyboard or from a file, and I read it like this:
How would that implement into readRouteData? Just like I did above? And then inside of readRouteData my code would look like:
Yes and yes.
If you wanted to, you could also call your function like this:
That's the flexibility part.