Source Code for "Standard C++ IOStreams and Locales"


Contents

1. Foreword
2. Purpose of the Examples
3. Coding Conventions
a. Names of Files
i. cpp - Files
ii. h - Files
b. Contents of cpp - Files
c. Relation between Source Code and Book Pages
d. Enabling / Disabling / Switching Code Segments
e. Deviations from Book's Code
4.a. Table: Page Covered by Example
b. Include Graph
5. Directory Organization
6. Further Questions  



1. Foreword

After reading this excellent book about IOStreams and enjoing the beautiful technics described there I wanted to find out the work arounds to make them run under the Visual C++ 6 compiler. That was the compiler I used at work. Fortunately (for me) I could read on Angelika Langer's homepage that she did not find the time do provide examples but she wants to do so. So I told her about my plan to write the examples. She promised to help me and kept this promise.

Sometimes it was really hard to develop with that compiler. If something did not compile or run I wondered if it was my insufficient understanding of C++, if there was a compiler bug or if there was a mistake in the book.

During that time of mental pains the Visual C++.Net came up and I got a much more suitable environment to develop the examples. With the better environment it became easier to develop the examples, so easy that it became possible to finish them. The examples were since then developed with the MVC.NET for a lot of C++ constructs do not run with the VC++ 6.


Though the disclaimers identify me as author the examples should be seen as a two - person project. One person had the necessary capacities to do the work, that was my part. The other person had the neccessary C++ knowledge and symathetic understanding to help and encourage a sometimes very confused and helpless worker. This second person is Angelika Langer, who really is willing to share her knowledge with her readers. I always enjoyed the freedom to ask her everything, sometimes even stupid questins. At this place I want to say many thanks to her for support and encouraging.

Many thanks I want to say to my employer, SAE IT-systems for the great tolerance of my researching projects.

Developing the examples enlarged my respect toward Angelika Langer and Klaus Kreft. They had no suitable compiler to test the code they wrote in their book. Writing code without the chance to test it is very error prone, of course. Later with help of the compiler it was psooible to find some errors in the book, errors I did not find during studying it. After the errors were detected by the compiler I often did not understand what was wrong there. With there was no compiler to test the code it is a great achievement by Angelika Langer and Klaus Kreft to write the code with only such few errors.
-- Klaus Wittlich --


2. Purpose of the Examples

The examples were provided to learn from book, enjoy them and play with them. You shurely will have the best benefits from them if you try to run them on your own computer, modify them and see what happens.

Code that is not intended to perform some actions is not part of the examples. That type of code is e.g. pure class definitions without function implementations.

In the *.h files you will find a comment that can be used for your own examples for copy - paste - including. In the header files you will find a comment like
/*
#include filename.h
*/
in filename.h. You can copy this comment to include it into your own file. This helps avoiding including the wrong header as a result of a typo.

In the source files you find the disclaimer:

Based on source code published in the book "Standard C++ IOStreams and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by Addison Wesley Longman, Inc.

Permission to use, copy, and modify this software for any non-profit purpose is hereby granted without fee. Neither the author of this source code, Klaus Wittlich, nor the authors of the above mentioned book, Angelika Langer and Klaus Kreft, nor the publisher, Addison Wesley Longman, Inc., make any representations about the suitability of this software for any purpose.It is provided "as is" without express or implied warranty.


3. Coding Conventions

3.a Names of Files

3.a.i. cpp - Files

The cpp - files are named to their pages, exNNN, where NNN is the page this example deals with. E. g. ex013.cpp is the example from page 13.
For some pages more than one example is required. In this case the examples are named exNNNa.cpp, exNNNb.cpp etc.

In cases the code of an example - cpp file in not fully within one page of the book the first page of the book is used for thename. E. g. ex328b.cpp
contains sample code from page 328 and 329.

Some code is removed into include files. In these cases NNN is the first page touched by the cpp file, not by the include files.

At the bottom of each cpp - FIle you find sample input and output for the program.


3.a.ii. h - Files

h - files are named after the class they contain and the (first) page that class occurs. Several classes are refined with incresing page number.
So the filenames of h - files have the format Classname_Page.h, e. g. date_170.h. That means: class date with version from page 170.


3.b. Contents of cpp - Files

cpp - files always contain one main() function. They are intendet to be the source code of a fully running program.

At their end they have a comment what their input and their output are.

3.c. Relation between Source Code and Book Pages

Code from a book's page is sandwitched between two comment lines
// p. NNN {{{
and
// }}}
where NNN is the page of the book.

E. g.

// p. 270 {{{
locale global;
cout << "global: " << global.name() << endl;
// }}}

3.d. Enabling / Disabling / Switching Code Segments

The examples are intended to play with them. In some cases it is useful to activate a code segment that is commented out and recompile the file.
Theses code segments to be enabled / disabled aresandwiched between lines
/*
Some Code
//*/


or

/*
Some Code
//*/


All you have to do to activate "Some Code" is to toggle from /* //* and vice versa. (You only need to remove / add onechar in your source code.)

Some examples offer you coices between two possible code segments to compare them. They are sandwiched between three comment lines:

/*
Choice 1
/*/
Choice 2
//*/


By toggeling /* to //* you select your code choices by adding / removing only one /


3.e. Deviations from Book's Code

if (condition)
return;
the code is put into main and is change to
int main()
{
...
if (condition)
return 0; // !!! main retuns int
...
}
        Deviations are commented with "// !!!" - Comments.

Additions of code segments are sandwitched between "// {{{" and "// }}}" braces. They have no page hint p. NNN.




			

4.a. Table: Page Covered by Example

PAGE

EXAMPLE(S)

COMMENT

Preface, xviii

ex026.cpp

Code is identic with p. 26

Preface, xxv

ex026.cpp

Code is idenstic with p. 26

14

ex014a.cpp, ex014b.cpp

IOStreams have no put function, so this is code is not part of the examples.

81

template<class charT ... is the same as p. 80.

121

No example provided for the code in the book shows only the priciple of the get function and is not intended to show something executable.

122

No example provided for the code in the book shows only the priciple of the get function and is not intended to show something executable.

147

For class date this page is no example provided. You find p. 148 a better version of class date.
Testcode second half p. 147 is repeated p. 149. Use the example there.

161 - 196

ex161.cpp

170 - 176

ex170.cpp

176

For the second half of the page no example is not provided for only the principle is shown in the code.

177

No example is provided for here only the architecture of the manipulators ist shown.

182

For the code snippet at the bottom of the page there is no example provided. That code snippet only shows the idea of what is needed. The implementation what is needed can be found p. 183

188, 189

ex187.cpp

190

ex181.cpp, ex187.cpp

193

No example, the code snippet shows the goal of the next steps. The effect of that code is similar to that of p. 221

196

ex196.cpp, ex207.cpp

defaultPatt: ex221.cpp

For the top code snippet of p. 196 no example is provided for it is a subset of the bottom code that page.

198

The setfmt_helper function is repeted p. 203, the class setfmt_helper has only slight differences to the sample code p. 203 / 204.Therefore no example is provided for p. 198

199

No example is provided. The book writes about the code: "It could like this:" A better version can be found p. 204.

202

Code is repeated p. 204, so see example for p. 204

203

Code snippet upper half of page: The code is repeated p. 204. The other code can be found in examples ex207.cpp and ex210.cpp .

204

ex207.cpp, ex210.cpp

205

ex207.cpp, ex210.cpp, ex221.cpp

206

ex207.cpp, ex210.cpp, ex221.cpp

209

No example provided.

210

ex210.cpp, ex221.cpp

212

ex210.cpp

213

No example provided.

214

No example provided for it is only a scetch here.

215, 216

ex221.cpp

217

Top of page ex221.cpp

Bottom: No example, code was repeated from p. 210

219

No example, the annotation from book "The compiler would complain ..." states out that this is not executable code

220

ex221.cpp

222

ex221.cpp

229

ex234.cpp, ex239.cpp

230 - 235 top of page

ex234.cpp

235 bottom of page

ex236.cpp, ex239.cpp

237-239 main

ex236.cpp

239 inbuf - 243

ex239.cpp

270

ex269.cpp
bottom: ex270.cpp

315

The use of decimal point was shown in ex300.cpp, so no new example was provided.

316

ex316.cpp, ex317.cpp

317

ex316.cpp, ex317.cpp , ex323.cpp

318

ex316.cpp, ex318.cpp, ex323.cpp

322

Code is identical with p. 309 and 310, so no new example is provided.

324

No example provided for the code here only shows the principle. This principle is applied p. 321 bottom

329

ex328b.cpp

333, 335 - 342

ex342.cpp

Note: do_put taken from p. 335 instead that version from p. 337 for at p. 337 it is a pure virtual function




4.b. Include Graph

The include graph only contains files covered by the example, not files shipped with the compiler. The arrow file_a.h --> file_b.* means file_a.h is included by file_b.* Examples that do not include a header provided by the examples are not mentioned in this graph.

The diagram showing dependencies among include files is also available in pdf format: Include Graph (PDF  8 KB).

include diagram page 1
include diagram page 2




5. Directory Organization

Directory "examples" contains an empty Visual C++.net project where you can insert a source cpp - file. In this directory are all files that are touched by the examples, too. That are those files that are used for input and output.

Directory "examples/doc" contains includes pdf and gif files for this document and a version number. If I detect errors I will try to fix them and increase the version number.  

Directory "examples/inc" contains all included headers.

Directroy "examples/src" contains all executable source code for all examples. Each cpp - file has its own main function. Each main fununction has a return 0; at its end. That is a good point to set a break point and to enjoy the output before the DOS - box disappears.



6. Further Questions

If you have further questions or annotations about the examples feel free to contact me ("Klaus Wittlich" <Klaus_Wittlich@sae.de> ). As long as I will not get too much feedback I surely will find the time to answer. If you have questions concerning the C++ background of the examples it will better to ask Angelika Langer ("Angelika Langer" <langer@camelot.de> ), she knows much more about it than I do.