[ale] Q: directing stream I/O _the_C++_way_
Fletch
fletch at phydeaux.org
Sat Nov 27 20:52:07 EST 2004
>>>>> "John" == John Mills <johnmills at speakeasy.net> writes:
John> ALErs - I want to optionally start a C++ program with the
John> name of a file for its log activity, else have the output
John> sent to the console as presently. (I use 'cout'). What's a
John> simple way to alternatively connect an output stream to
John> 'stdout' or a named file? (For my own learning, I would
John> rather use "C++-style" than "C-style" operators.)
I want to say that you should be able to declare an ostream and assign
either an ofstream or cout as desired.
ostream& log;
if( logfilename ) {
ofstream logfile( logfilename.c_str() );
log = logfile;
} else {
log = cout;
}
Granted that's not perl so I can't guarantee the syntax is exactly
correct . . . :)
John> A pointer to a nice on-line manual for this type inquiry
John> would also be nice.
Not online, but several people at work have this book and it's been
helpful the handfull of times I've needed to poke at something C++.
_The C++ Standard Library: A Tutorial and Reference_
http://www.amazon.com/exec/obidos/tg/detail/-/0201379260
--
Fletch | "If you find my answers frightening, __`'/|
fletch at phydeaux.org | Vincent, you should cease askin' \ o.O'
| scary questions." -- Jules =(___)=
| U
More information about the Ale
mailing list