Why no diagnostic for stream << stream?

A

Anand Hariharan

Missing a .str() caused me two hours of work today. The code was like
so:

ostringstream ss;
ss << "Whatever " << Foo;

ofstream MyFile;
// ...

MyFile << ss; // should have been ss.str()

Am wondering why a diagnostic isn't required to catch this error? How
big a deal is it for an implementation to catch this?

thanks,
- Anand
 
R

red floyd

Missing a .str() caused me two hours of work today.  The code was like
so:

ostringstream ss;
ss << "Whatever " << Foo;

ofstream MyFile;
// ...

MyFile << ss; // should have been ss.str()

Am wondering why a diagnostic isn't required to catch this error?  How
big a deal is it for an implementation to catch this?

I believe that it's because ostream has an implicit converson to
void*, for things like:

if (os << xomething)

And there's an ostream& operator<<(ostream&, const void*)
 
A

Anand Hariharan

I believe that it's because ostream has an implicit converson to
void*, for things like:

if (os << xomething)

And there's an ostream& operator<<(ostream&, const void*)

Thank you,

- Anand
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top