[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



Thanks for the answer.

On Sat, 27 Nov 2004, Fletch wrote:

> >>>>> "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;
> }

That's what I was hoping for - I was trying to guess the syntax, but 
hadn't that I could use 'cout' like that.

> Granted that's not perl so I can't guarantee the syntax is exactly
> correct . . . :)

Sorry - I'm not smart enough to ask Perl questions.
 
>     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_
&gt; <a  rel="nofollow" href="http://www.amazon.com/exec/obidos/tg/detail/-/0201379260";>http://www.amazon.com/exec/obidos/tg/detail/-/0201379260</a>

Thanks for this also. I'm still with Stroustrup's and Lippman's books - 
good, but didn't get me over this.

 - Mills
   john.m.mills at alum.mit.edu


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="01033" href="msg01033.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
<ul><li><em>From:</em> fletch at phydeaux.org (Fletch)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg01035.html">[ale] Linksys WRT54g alternate firmware</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg01037.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg01033.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg01037.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#01036"><strong>Date</strong></a></li>
<li><a href="threads.html#01036"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>