I am porting some C++ code from Unix to Linux (Red Hat).
I have run into the following pattern:
ostream& myfunction(ostream& os)
{
if (os.opfx())
{
os << mydata;
os.osfx();
}
return os;
}
The functions opfx
and osfx
are not available under Red Hat 4.5. I saw a suggestion here to use the ostream::sentry
functionality:
ostream& myfunction_ported(ostream& os)
{
ostream::sentry ok(os);
if (ok)
{
os << mydata;
}
return os;
}
I see from here that the purpose of opfx
is to verify the stream state before flushing it and continuing.
My questions:
I thought the ostream
functions already checked the stream state before operating on the stream. Is this true? Was this not true at some point?
Is replacing opfx
with sentry
necessary? What does sentry
give me that operator<<
doesn't give me already?