[ale] Q: directing stream I/O _the_C++_way_
John Mills
johnmills at speakeasy.net
Sat Nov 27 22:16:46 EST 2004
Fletch --
On Sat, 27 Nov 2004, Fletch wrote:
> I want to say that you should be able to declare an ostream and assign
> either an ofstream or cout as desired.
>
> ostream& log; <-------[initializing to 'cout' => same whine]-----+
> |
> if( logfilename ) { |
> ofstream logfile( logfilename.c_str() ); |
> log = logfile; |
^^^^^^^^^^^^^---- This doesn't compile. I get: |
V
Switchbox.cpp:38: `logging' declared as reference but not initialized
/usr/include/c++/3.2.3/bits/ios_base.h: In member function
`std::basic_ios<char, std::char_traits<char> >& std::basic_ios<char,
std::char_traits<char> >::operator=(const std::basic_ios<char,
std::char_traits<char> >&)':
/usr/include/c++/3.2.3/bits/ios_base.h:427: `std::ios_base&
std::ios_base::operator=(const std::ios_base&)' is private
Switchbox.cpp:133: within this context
make: *** [Switchbox.o] Error 1
> } else {
> log = cout;
> }
- John Mills
john.m.mills at alum.mit.edu
More information about the Ale
mailing list