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

[no subject]



    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_
<a  rel="nofollow" href="http://www.amazon.com/exec/obidos/tg/detail/-/0201379260";>http://www.amazon.com/exec/obidos/tg/detail/-/0201379260</a>

-- 
Fletch                | &quot;If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
                      |  scary questions.&quot; -- Jules                =(___)=
                      |                                               U


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="01036" href="msg01036.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
<ul><li><em>From:</em> johnmills at speakeasy.net (John Mills)</li></ul></li>
<li><strong><a name="01037" href="msg01037.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
<ul><li><em>From:</em> johnmills at speakeasy.net (John Mills)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="01024" href="msg01024.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
<ul><li><em>From:</em> johnmills at speakeasy.net (John Mills)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg01032.html">[ale] help with rm (yes, I'm embarrassed about this)</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg01034.html">[ale] FTP setup problem...</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg01024.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg01036.html">[ale] Q: directing stream I/O _the_C++_way_</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#01033"><strong>Date</strong></a></li>
<li><a href="threads.html#01033"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

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