a quick ofstream question

Dietmar Kuehl dietmar.kuehl@claas-solutions.de
Tue Aug 24 18:53:00 GMT 1999


Hi,
At 18:19 24.08.99 -0700, Igor Markov wrote:
>    while porting code from CC4.2 to g++2.95(.1), I noticed that
>      ofstream("filename") << myVar;

This should not work: You cannot bind a temporary to a non-const reference.
However, the first argument to the output operator is normally a non-const
reference to 'ostream&' (or 'basic_ostream<cT, traits>'). g++ is correct,
CC4.2 is not. I guess CC5.* is also correct, ie. will reject this code.

>    It is conceivable that g++ does not want to apply a non-const
>    op<< to a temporary, but I was wondering if this is according 
>    to the C++ standard (if not, does V3 allow this).

Yes, it is according to the standard.

Dietmar


More information about the Libstdc++ mailing list