Various C++ Examples (including IPC)  Version: 1.0.0
streambuf.cc File Reference

Demonstration of streambuf inheritance. More...

#include <iostream>
#include <cstdio>
Include dependency graph for streambuf.cc:

Go to the source code of this file.

Classes

class  dmsg
 Demonstration of streambuf inheritance. More...
 

Functions

int main (int argc, char **argv)
 

Detailed Description

Demonstration of streambuf inheritance.

Purpose:
Program that demonstrates inheriting from streambuf to act just like cout. The program comes from chapter 13 of "The C++ Standard Library" (Josuttis).

Also demonstrates the values of various types of variables when instantiated.

Definition in file streambuf.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 47 of file streambuf.cc.

References dmsg::i, and dmsg::p.

48 {
49  dmsg X;
50  std::ostream out(&X);
51 
52  out << "xxx "
53  << 123
54  << " yyy"
55  << std::endl;
56 
57  std::cout << "blah" << std::endl;
58 
59 
60  /* demonstrate compound input from a stream
61  (for example type "2xx4y [enter]" at the prompt)
62  */
63  int i;
64  char ch;
65  std::cout << std::endl;
66  std::cout << "i="<< i << "|ch="<<ch<<std::endl;
67  std::cout << "prompt:";
68  std::cin >> i >> ch;
69  std::cout << "i="<< i << "|ch="<<ch<<std::endl;
70 
71  /* demonstrate the contents of variables when they are created
72  */
73  dmsg *msg_p = new dmsg();
74 
75  if(msg_p->p == NULL)
76  std::cout << "msg_p->p is NULL" << std::endl;
77 
78  if(msg_p->i == 0)
79  std::cout << "msg_p->i is ZERO" << std::endl;
80 
81  delete msg_p;
82 
83 
84  int *i_p;
85 
86  if(i_p)
87  std::cout << "i_p is VALID" << std::endl;
88 
89  if(i_p == NULL)
90  std::cout << "i_p is NULL" << std::endl;
91  else
92  if(i_p == 0)
93  std::cout << "i_p is ZERO" << std::endl;
94 
95  i_p = new int;
96 
97  if(*i_p == 0)
98  std::cout << "*i_p is ZERO" << std::endl;
99  else
100  std::cout << "*i_p=" << *i_p <<std::endl;
101 
102  delete i_p;
103 }
int * p
Definition: streambuf.cc:21
int i
Definition: streambuf.cc:20
Demonstration of streambuf inheritance.
Definition: streambuf.cc:17