PROBLEM: conditional initialisation of stream
Posted on 1997-05-03
I have just spent a frustrating time sorting sorting out a problem that occurred in the following structure.....
#include <everything that's needed>
ostrstream os ;
if (condition) ostrstream os (buf, 100, ios::out) ;
if (condition) os << "text string" ;
What I found is that even with condition true, no data was written to the stream. When I took the ostrstream initialisation outside the conditional, it worked fine.
Appreciate that this may be judged a platform dependent query, but my first question is: does the initialisation of a stream inside a conditional violate any fundamental rule of C++? No (BC3.1) compiler errors or warnings were issued. My reference (Stroustrup) seems not to refer to the situation.