I have a suspicion this is a trivial problem, but I can't figure out the vocab to do a decent google/forums search on it.
I'm writing a class member function that takes an ostream as an argument and then outputs some formatted private member data. I'm curious if there is a way to check to see if it is valid to use the stream insertion operator, for example if the client driver passes an ifstream that hasn't been succesfully opened. I don't really understand that possible states and flags of an ostream, and the references I've looked through so far deal with file streams and standard output streams (cout/cerr) as different topics so I'm not which information applies to all ostreams.
My code looks something like this:
Code:
void MyClass::printData(std::ostream& out) {
// if (cannot write to out)
// throw domain_error; // or more appropriate exception?
out << data << std::endl;
return;
}
Thank you