File: tut3.html

package info (click to toggle)
libcwd 1.0.4-1.1
  • links: PTS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 8,136 kB
  • ctags: 10,313
  • sloc: cpp: 23,354; sh: 9,798; ansic: 1,172; makefile: 852; exp: 234; awk: 11
file content (85 lines) | stat: -rw-r--r-- 2,784 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML LANG="en-us">
<HEAD>
<META name="Author" content="Carlo Wood">
<META http-equiv="content-type" content="text/html; charset=iso-8859-1">
<META http-equiv="content-script-type" content="text/javascript">
<TITLE>libcwd: The C++ Debugging Support Library - Tutorial</TITLE>
<SCRIPT SRC="../scripts/detect_browser.js"></SCRIPT>
<SCRIPT>need_style_tutorial=1</SCRIPT>
<SCRIPT SRC="../scripts/load_style_sheets.js"></SCRIPT>
</HEAD>
<BODY>

<TABLE class="header" height=64 width="100%" cellpadding=0 cellspacing=0 border=0>
  <TR>
    <TD width=237 valign=top>
      <IMG valign=top src="../images/libcwd_logo.png" alt="" align=left border=0>
    </TD>
    <TD width="100%" align=center>
      <DIV class="header-title">
      The C++ Debugging Support Library
      </DIV>
      <DIV class="header-copyright">
      By Carlo Wood, &copy;1999 - 2003.
      </DIV>
    </TD>
  </TR>
  <SCRIPT>if (is_mozilla4) document.write("<TR><TD colspan=2 height=19 valign=bottom><HR SIZE=2 NOSHADE></TD></TR>");</SCRIPT>
</TABLE>

<DIV class="body">

<H2>Tutorial 3: Setting the <CODE>ostream</CODE></H2>

<P>You can write the debug output to any given ostream.&nbsp;
The following example opens a file <SPAN class="filename">log</SPAN> and
uses it to write its debug output to.</P>

<P class="download">[<A HREF="log_file.cc">download</A>]</P>

<P>Compile as: <CODE>g++ -DCWDEBUG log_file.cc -lcwd -o log_file</CODE></P>
<PRE>
#include &quot;sys.h&quot;		// See tutorial 2.
#include &lt;fstream&gt;
#include &quot;debug.h&quot;		// See tutorial 2.

int main(void)
{
  Debug( dc::notice.on() );
  Debug( libcw_do.on() );

#ifdef CWDEBUG
  std::ofstream file;
  file.open("log");
#endif

  // Set the ostream related with libcw_do to `file':&nbsp;&nbsp;
  <SPAN class="highlight">Debug( libcw_do.set_ostream(&amp;file) );</SPAN>

  Dout(dc::notice, "Hippopotamus are heavy");

  return 0;
}
</PRE>

<P>Debug code like the definition of the debug file <CODE>file</CODE>,
should be put between <CODE>#ifdef CWDEBUG ... #endif</CODE> as usual.&nbsp;
This isn't needed for <CODE>Debug()</CODE> or <CODE>Dout()</CODE>
because these macros are automatically replaced with white space
when <CODE>CWDEBUG</CODE> is not defined.</P>


</DIV>
<P class="line"><IMG width=870 height=19 src="../images/lines/hippo.png"></P>
<DIV class="buttons">
<A HREF="tut2.html"><IMG width=64 height=32 src="../images/buttons/lr_prev.png" border="0"></A>
<A HREF="index.html"><IMG width=64 height=32 src="../images/buttons/lr_index.png" border="0"></A>
<A HREF="tut4.html"><IMG width=64 height=32 src="../images/buttons/lr_next.png" border="0"></A>
</DIV>

<ADDRESS>Copyright &copy; 2001, 2002 Carlo Wood.&nbsp; All rights reserved.</ADDRESS>

</BODY>
</HTML>