October 31, 2002
In article <appsp4$2c0v$1@digitaldaemon.com>, bw says...
>
>hmmm, actually now that i took a better look, seems you can assign an ofstream object directly to cout...

Thanks for suggestions. Obviously, I would prefer the more consistent cout.rdbuf(streambuf*) approach, but cout = filebuf& works so... Just to wrap it up, the DM way to redirect cout to a file or other streambuf based object is to use operator= like..

ofstream* fout = new ofstream("Message.log");
streambuf* coutbuf = cout.rdbuf();
cout = *fout;
cout << "This ends up in the file! No output to console." << endl;
cout = coutbuf;
delete fout;

Thanks again.

Richard

>ofstream log("Message.log");
>cout=log;
>cout << "this text goes to message.log\n";
>
>
>In article <aposs0$nun$1@digitaldaemon.com>, bw says...
>>
>>ofstream log("Message.log");
>>streambuf* out = log.rdbuf();
>>cout=out;
>>cout << "this is text for cout";


1 2
Next ›   Last »