Repository navigation
Expand file tree
/
Copy pathdata-small.txt
More file actions
1717 lines (1713 loc) · 109 KB
/
Copy pathdata-small.txt
File metadata and controls
1717 lines (1713 loc) · 109 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]">
<meta name="Author" content="Angelika Langer and Klaus Kreft">
<title>Errata (1st Printing)</title>
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#113E79" vlink="#677DAD" alink="#008080">
<a NAME="Top"></a><a NAME="IOStreamsErrata1stPrinting"></a>
<br>
<table BORDER=0 CELLPADDING=10 WIDTH="100%" >
<tr>
<td>Thanks to everybody who took the time to send us an email to draw our
attention to mistakes and typos in the book. We thank our readers for reading
the book so carefully and attentively that you could spot the flaws. Thanks
a lot!
<p>Below is a list of errors that have have been identified in the first
printing. All of these errors should be corrected in the second printing.
<p>Feel free to send us <a href="mailto:[email protected]">email</a> as
soon as you detect another mistake.
<br>
<table BORDER=0 CELLSPACING=0 CELLPADDING=0 COLS=3 WIDTH="75%" >
<tr VALIGN=TOP>
<td><a href="#21">page 21</a>
<br><a href="#22">page 22</a>
<br><a href="#33">page 33</a>
<br><a href="#35">page 35</a>
<br><a href="#37">page 37</a>
<br><a href="#38">page 38</a>
<br><a href="#39">page 39</a>
<br><a href="#40">page 40</a>
<br><a href="#42">page 42</a>
<br><a href="#43">page 43</a>
<br><a href="#45">page 45</a>
<br><a href="#48">page 48</a>
<br><a href="#50">page 50</a>
<br><a href="#53">page 53</a>
<br><a href="#55">page 55</a>
<br><a href="#58">page 58</a>
<br><a href="#70">page 70 & 77</a>
<br><a href="#73">page 73</a>
<br><a href="#85">page 85</a>
<br><a href="#89">page 89 & 90</a>
<br><a href="#92">page 92</a>
<br><a href="#115">page 115</a>
<br><a href="#144">page 144</a>
<br><a href="#152">page 152 -155</a>
<br><a href="#156">page 156</a>
<br><a href="#160">page 160</a>
<br><a href="#161">page 161</a></td>
<td><a href="#162">page 162</a>
<br><a href="#171">page 171</a>
<br><a href="#177">page 177</a>
<br><a href="#180">page 180</a>
<br><a href="#188">page 188</a>
<br><a href="#221">page 221</a>
<br><a href="#222">page 222</a>
<br><a href="#225">page 225 - 248</a>
<br><a href="#233">page 233</a>
<br><a href="#240">page 240</a>
<br><a href="#241">page 241</a>
<br><a href="#242">page 242</a>
<br><a href="#245">page 245</a>
<br><a href="#255">page 255</a>
<br><a href="#272">page 272</a>
<br><a href="#275">page 275</a>
<br><a href="#281">page 281</a>
<br><a href="#284">page 284</a>
<br><a href="#286">page 286</a>
<br><a href="#287">page 287</a>
<br><a href="#288">page 288</a>
<br><a href="#296">page 296</a>
<br><a href="#298">page 298</a>
<br><a href="#305">page 305</a>
<br><a href="#315">page 315</a>
<br><a href="#316">page 316</a></td>
<td><a href="#317">page 317</a>
<br><a href="#322">page 322</a>
<br><a href="#323">page 323</a>
<br><a href="#325">page 325</a>
<br><a href="#327">page 327 & 333</a>
<br><a href="#335">page 335</a>
<br><a href="#336">page 336</a>
<br><a href="#338">page 338 & 339</a>
<br><a href="#456">page 456</a>
<br><a href="#464">page 464</a>
<br><a href="#479">page 479</a>
<br><a href="#487">page 487</a>
<br><a href="#502">page 502</a>
<br><a href="#508">page 508</a>
<br><a href="#511">page 511</a>
<br><a href="#511&513">page 511 & 513</a>
<br><a href="#512">page 512 & 514</a>
<br><a href="#516">page 516</a>
<br><a href="#549">page 549</a>
<br><a href="#565">page 565</a>
<br><a href="#615">page 614 & 615</a>
<br><a href="#621">page 621</a>
<br><a href="#632">page 632</a>
<br><a href="#636">page 636</a>
<br><a href="#638">page 638</a>
<br><a href="#640">page 640</a></td>
</tr>
</table>
<img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="21"></a><b>page 21:</b>
<br><i>The example uses a C-style string for demonstration of the effect
of width. However, what we describe is wrong, because the maximum number
of extracted characters is <tt>width()</tt> for C++ strings and <tt>width()-1</tt>
for C string. In our example, only 9 instead of 10 characters would
be extracted. We should have better been using a C++ string. The example
but be corrected to:</i>
<p><tt>// input</tt>
<br><tt>int i; <b><blink><font color="#FF6666">string s;</font></blink></b></tt>
<p><tt>cin.width(10);</tt>
<br><tt>cin >> i >> s;</tt>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Scott Barrett, Principal Member
Technical Staff </font></font>
<br><font face="Trebuchet MS"><font size=-2>PAR Government Systems Corporation,
Rome, NY, May 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="22"></a><b>page 22:</b>
<br><i>The code sample for demonstrating the effect of the field width
setting is misleading because the leading white spaces are not visible.
It should be changed to:</i>
<p><font size=-1> <font face="Courier New,Courier">// output</font></font>
<br><font face="Courier New,Courier"><font size=-1> int i; char s[11];</font></font>
<p><font face="Courier New,Courier"><font size=-1> cout.width(10);</font></font>
<br><font face="Courier New,Courier"><font size=-1> <b><blink><font color="#FF6666">cout.fill('.');</font></blink></b></font></font>
<br><font face="Courier New,Courier"><font size=-1> cout <<i
<< s;</font></font>
<p> If the variables <font face="Courier New,Courier">i</font> and
<font face="Courier New,Courier">s</font>
have the following values:
<br> <font face="Courier New,Courier"><font size=-1>i: 123</font></font>
<br> and
<br> <font face="Courier New,Courier"><font size=-1>s: "abc"</font></font>
<p> then the output is
<p> <font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">.......</font></blink></b>123abc</font></font>
<p>that is, seven <b><blink><font color="#FF6666">dots</font></blink></b>
followed by the three digits representing the value of <font face="Courier New,Courier">i</font>,
followed by the character sequence contained in <font face="Courier New,Courier">s</font>.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Bernd Mohr / Research Centre
Juelich, ZAM, Germany, August 2000 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="33"></a><b>page 33:</b>
<br><i>The first two paragraphs in the section on "The Stream State's Effect
on Insertion and Extraction" on page 33 is misleading and should read:</i>
<p> The stream state affects the behavior of the IOStreams
operations. By convention, all IOStreams operations have no effect once
the stream state indicates an error situation. More specifically, I/O operations
do nothing if the initial stream state at the time of their invocation
includes either <font face="Courier New,Courier">failbit</font>, <font face="Courier New,Courier">badbit</font>,
or <font face="Courier New,Courier">eofbit</font>, and input and output
operations stop as soon as one of the stream state flags is set.
<br> Note the interesting effect of the <font face="Courier New,Courier">eofbit</font>:
Extractions do not only stop in case of an error (<font face="Courier New,Courier">failbit</font>
or <font face="Courier New,Courier">badbit</font>), but also when the end
of the input stream is reached (<font face="Courier New,Courier">eofbit</font>).
Insertions typically stop only in case of an error, because no output operation
ever sets the <font face="Courier New,Courier">eofbit</font>. If, however,
the <font face="Courier New,Courier">eofbit</font> has been set before
the output operation is invoked, then the attempted insertion will fail
and have no effect. This can happen in bidirectional streams when an extraction
that reached the end of the input is followed by an insertion to the stream,
which then has the <font face="Courier New,Courier">eofbit</font> set due
to the preceeding extraction. For this reason the <font face="Courier New,Courier">eofbit</font>
in addition to the error flags <font face="Courier New,Courier">failbit</font>
and <font face="Courier New,Courier">badbit</font> stops operations on
input and bidirectional streams, but is irrelevant for operations on output
streams.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Bernd Mohr / Research Centre
Juelich, ZAM, Germany, August 2000 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="35"></a><b>page 35:</b>
<br><i>In the middle of page 35 we describe the effect of the cast operator
that converts a stream to type <tt>void*</tt> saying the following: </i>
<p>The cast operator <tt>operator void*()</tt> returns a zero pointer value
if <tt>failbit</tt> or <tt>badbit</tt> are set, and zero otherwise.
<p><i>Of course, this is nonsense. It must be corrected to:</i>
<p>The cast operator <tt>operator void*()</tt> returns a zero pointer value
if <tt>failbit</tt> or <tt>badbit</tt> are
<br>set, and <b><blink><font color="#FF6666">nonzero</font></blink></b>
otherwise.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Robert P. Goddard, Senior Physicist,
University of Washington, Seattle, WA, January 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="37"></a><b>page 37:</b>
<br>An alternative to wrapping the critical operations into a try block
is to suppress exceptions, execute all critical operations, and activate
them afterwards. Here is an example:
<p><font face="Courier New,Courier"><font size=-1>cout.exceptions(ios_base::goodbit);</font></font>
<br><b><blink><font face="Courier New,Courier"><font color="#FF6666"><font size=-1>cout
<< x;</font></font></font></blink></b>
<br><font face="Courier New,Courier"><font size=-1>// do lots of other
stream I/O</font></font>
<br><font face="Courier New,Courier"><font size=-1>try {cout.exceptions(ios_base::badbit
| ios_base::failbit);}</font></font>
<br><font face="Courier New,Courier"><font size=-1>catch(ios_base::failure&
exc)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ if (cout.bad())</font></font>
<br><font face="Courier New,Courier"><font size=-1> { </font></font>
<br><font face="Courier New,Courier"><font size=-1>
// unrecoverable error</font></font>
<br><font face="Courier New,Courier"><font size=-1>
...</font></font>
<br><font face="Courier New,Courier"><font size=-1>
throw;</font></font>
<br><font face="Courier New,Courier"><font size=-1> } </font></font>
<br><font face="Courier New,Courier"><font size=-1> else
if(cout.fail())</font></font>
<br><font face="Courier New,Courier"><font size=-1> { </font></font>
<br><font face="Courier New,Courier"><font size=-1>
// retry</font></font>
<br><font face="Courier New,Courier"><font size=-1>
...</font></font>
<br><font face="Courier New,Courier"><font size=-1>
return;</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<br><font face="Courier New,Courier"><font size=-1>}</font></font>
<p>The call to <font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">cout</font></blink></b>.exceptions(ios_base::goodbit)</font></font>
clears the exception mask and deactivates all exceptions. All of the subsequent
statements are executed because no exception can be thrown. Eventually,
the call to <font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">cout</font></blink></b>.exceptions
(ios_base::badbit | ios_base::failbit)</font></font> is wrapped into a
try block and raises an <font face="Courier New,Courier"><font size=-1>ios_base::failure
</font></font>exception
in case that any of the previously executed operations failed.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>students of an IOStreams seminar
held at SAP AG in St. Leon-Rot, Germany, April 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="38"></a><b>page 38:</b>
<br>To reset the stream state to good after an error has occured either
<font face="Courier New,Courier"><font size=-1>clear()</font></font>
or
<font face="Courier New,Courier"><font size=-1>clear(goodbit) </font></font>can
be used . Let us add a call to <font face="Courier New,Courier"><font size=-1>clear()</font></font>
to the example above where we suggest to retry I/O processing. The code
changes to:
<p> <font face="Courier New,Courier"><font size=-1>cout.exceptions(ios_base::goodbit);</font></font>
<br><font face="Courier New,Courier"><font size=-1> <b><blink><font color="#FF6666">cout
<< x;</font></blink></b></font></font>
<br><font face="Courier New,Courier"><font size=-1> // do lots of
other stream I/O</font></font>
<br><font face="Courier New,Courier"><font size=-1> try {cout.exceptions(ios_base::badbit
| ios_base::failbit);}</font></font>
<br><font face="Courier New,Courier"><font size=-1> catch(ios_base::failure&
exc)</font></font>
<br><font face="Courier New,Courier"><font size=-1> {
if (cout.bad())</font></font>
<br><font face="Courier New,Courier"><font size=-1>
{ </font></font>
<br><font face="Courier New,Courier"><font size=-1>
// unrecoverable error</font></font>
<br><font face="Courier New,Courier"><font size=-1>
...</font></font>
<br><font face="Courier New,Courier"><font size=-1>
throw;</font></font>
<br><font face="Courier New,Courier"><font size=-1>
} </font></font>
<br><font face="Courier New,Courier"><font size=-1>
else if(cout.fail())</font></font>
<br><font face="Courier New,Courier"><font size=-1>
{ </font></font>
<br><font face="Courier New,Courier"><font size=-1>
cout.clear(); </font></font>
<br><font face="Courier New,Courier"><font size=-1>
// redo <b><blink><font color="#FF6666">the</font></blink></b> stream I/O
that does not cause failure</font></font>
<br><font face="Courier New,Courier"><font size=-1>
return;</font></font>
<br><font face="Courier New,Courier"><font size=-1>
}</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<p><font face="Trebuchet MS"><font size=-2>error in code found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>students of an IOStreams seminar
held at SAP AG in St. Leon-Rot, Germany, April 2000</font></font>
<br><font face="Trebuchet MS"><font size=-2>typo in comment found by:</font></font>
<br><font face="Trebuchet MS"><font size=-2>Robert W. Hand, February 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="39"></a><b>page 39:</b>
<br><i>The comment in the code snippet on page 39 should read:</i>
<p><font face="Courier New,Courier"><font size=-1>
else if(cout.fail())</font></font>
<br><font face="Courier New,Courier"><font size=-1>
{ </font></font>
<br><font face="Courier New,Courier"><font size=-1>
cout.clear(); </font></font>
<br><font face="Courier New,Courier"><font size=-1>
// <b><blink><font color="#FF6666">redo those stream I/O operations that
do not cause failure</font></blink></b></font></font>
<br><font face="Courier New,Courier"><font size=-1>
return;</font></font>
<br><font face="Courier New,Courier"><font size=-1>
}</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Vikram bir Singh, September
2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="40"></a><b>page 40:</b>
<br><i>The first code example on page 40 should read:</i>
<p><font face="Courier New,Courier">ifstream source<b><blink><font color="#FF6666">("src.cpp")</font></blink></b>;</font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Jonathan Levinson, July 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="42"></a><b>page 42:</b>
<br><i>The last paragraph on page 42 is slightly misleading and should
read:</i>
<p><b><font face="Arial,Helvetica"><font size=-2>THE INITIAL FILE LENGTH</font></font></b><font face="Courier New,Courier">.
</font>The
open mode <font face="Courier New,Courier">trunc</font> (meaning
<i>truncate</i>)
sets the initial file length to zero, which has the effect of discarding
the file content. The <font face="Courier New,Courier">trunc</font> flag
is included in the default open mode of output file streams, so you
can omit the <font face="Courier New,Courier">trunc</font> flag and think
of the open mode <font face="Courier New,Courier">out</font> as being equivalent
to <font face="Courier New,Courier">out|trunc</font>. This only holds true
for output file streams. For bidirectional file streams, the <font face="Courier New,Courier">trunc</font>
flag must always be explicitly specified, i.e., you must say <font face="Courier New,Courier">in|out|trunc</font>,
if the file content is to be discarded.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Bernd Mohr / Research Centre
Juelich, ZAM, Germany, August 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="43"></a><b>page 43:</b>
<br><i>The last code example on page 43 should read:</i>
<p><font face="Courier New,Courier">fstream BiStr(<b><blink><font color="#FF6666">"poem.txt"</font></blink></b>,<b><blink><font color="#FF6666">ios_base::in|ios_base::out</font></blink></b>);</font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Clinton James, IT Director,
UCS Call One, Chicago, IL USA, July 2000 and</font></font>
<br><font face="Trebuchet MS"><font size=-2>Vikram bir Singh, September
2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="45"></a><b>page 45:</b>
<br><i>The first code example on page 45 should read:</i>
<p><font face="Courier New,Courier">// bidirectional file stream opened
<b><blink><font color="#FF6666">only
for input</font></blink></b></font>
<br><font face="Courier New,Courier">fstream BiFil("poem.txt", <b><blink><font color="#FF6666">ios_base::in</font></blink></b>);</font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Vikram bir Singh, September
2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="48"></a><b>page 48:</b>
<br>Typically, you use in-memory I/O if the information to be read is already
available in the form of a string, or if the formatted result will be processed
as a string. For example, to interpret the contents of a string as
an integer value, the code might look like this:
<p><font face="Courier New,Courier"><font size=-1> int i;</font></font>
<br><font face="Courier New,Courier"><font size=-1> if (istringstream("4711")
>> i)</font></font>
<br><font face="Courier New,Courier"><font size=-1> {</font></font>
<br><font face="Courier New,Courier"><font size=-1> //
i has the value: 4711</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<p>The equivalent operation in C would be a call to the <b><blink><font face="Courier New,Courier"><font color="#FF6666"><font size=-1>sscanf()</font></font></font></blink></b>
function. However, string streams are more powerful than <font face="Courier New,Courier"><font size=-1>sscanf()</font></font>,
because they use the full set of formatting facilities of IOStreams, including
internationalization for instance.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>students of an IOStreams seminar
held at SAP AG in St. Leon-Rot, Germany, April 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="50"></a><b>page 50:</b>
<br><i>A -- is printed as a plain - in the code snippet on page 50. The
code snippet should read:</i>
<p><tt> <font size=-1>// character buffer; can store lines of length
99</font></tt>
<br><tt><font size=-1> // note: input adds a terminating null character </font></tt>
<br><tt><font size=-1> const int line_buffer_size = 100;</font></tt>
<br><tt><font size=-1> char buffer[line_buffer_size];</font></tt>
<p><tt><font size=-1> int line_number = 0;</font></tt>
<br><tt><font size=-1> while (cin.getline(buffer, line_buffer_size,
'\n') // stream still good() ?</font></tt>
<br><tt><font size=-1> || cin.gcount())
// any characters read ?</font></tt>
<br><tt><font size=-1> {</font></tt>
<br><tt><font size=-1> int count = cin.gcount();</font></tt>
<p><tt><font size=-1> if (cin.eof())</font></tt>
<br><tt><font size=-1> // end of file
found; last line extracted</font></tt>
<br><tt><font size=-1> cout <<
"Partial final line"; </font></tt>
<br><tt><font size=-1> else if (cin.fail()) </font></tt>
<br><tt><font size=-1> { // max number of chars
was reached; line was longer 99 chars</font></tt>
<br><tt><font size=-1> cout <<
"Partial long line";</font></tt>
<br><tt><font size=-1> // clear stream
state so that we can continue reading</font></tt>
<br><tt><font size=-1> cin.clear(cin.rdstate()
& ~ios::failbit);</font></tt>
<br><tt><font size=-1> } else {</font></tt>
<br><tt><font size=-1> // don't include
newline in count</font></tt>
<br><tt><font size=-1> // mind: delimiter
was extracted and counted, but not stored </font></tt>
<br><tt><font size=-1> <b><blink><font color="#FF6666">count--;</font></blink></b></font></tt>
<br><tt><font size=-1> cout <<
"Line " << ++line_number;</font></tt>
<br><tt><font size=-1> }</font></tt>
<br><tt><font size=-1> cout << " (" << count <<
" chars): " << buffer << endl;</font></tt>
<br><tt><font size=-1> }</font></tt>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Igor V. Rafienko, Norway, September
2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="53"></a><b>page 53:</b>
<br><i>The last paragraph should read:</i>
<p>The error handling is omitted from the example. The functions <tt>tellp()/tellg()</tt>
indicate failure by returning the invalid stream position <tt>pos_type(-1)</tt>
and <tt>seekp()/<b><blink><font color="#FF6666">seekg()</font></blink></b></tt>
indicate failure by setting the stream state.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Wolfgang Kaisers, Germany,
July 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="55"></a><b>page 55:</b>
<br><i>A -- is printed as a plain - in the code snippets on page 55. The
code snippets should read:</i>
<p><tt><font size=-1> ofstream ostr("/tmp/fil"); </font></tt>
<br><tt><font size=-1> int i=10;</font></tt>
<br><tt><font size=-1> ostr << unitbuf;</font></tt>
<br><tt><font size=-1> while (<b><blink><font color="#FF6666">i--</font></blink></b>)</font></tt>
<br><tt><font size=-1> { ostr << i; }</font></tt>
<p><i><tt>and</tt></i>
<p><tt><font size=-1> ofstream ostr("/tmp/fil"); </font></tt>
<br><tt><font size=-1> int i=10;</font></tt>
<br><tt><font size=-1> while (<b><blink><font color="#FF6666">i--</font></blink></b>)</font></tt>
<br><tt><font size=-1> { ostr << i; </font></tt>
<br><tt><font size=-1> ostr.flush();</font></tt>
<br><tt><font size=-1> }</font></tt>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Igor V. Rafienko, Norway, September
2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="58"></a><b>page 58:</b>
<br><i>We failed to mention that sync_with_stdio is a member function of
ios_base; instead our code snippet suggests that is its a global function.
The corresponding section should read:</i>
<p>This synchronization is time consuming and for this reason might not
be desired in all situations. You can switch it off by calling
<p><tt> <b><blink><font color="#FF6666">ios_base::</font></blink></b>sync_with_stdio(false);</tt>
<p><b><blink><font color="#FF6666">where <tt>sync_with_stdio()</tt> is
a static stream member function defined in base class <tt>ios_base</tt>. </font></blink></b>
<p>After such a call the predefined streams will operate independently
of the C standard files, with possible performance improvements in your
C++ stream operations.
<br>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Igor V. Rafienko, Norway, September
2000</font></font>
<br><font face="Trebuchet MS"><font size=-2>further improvements suggestes
by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Robert P. Goddard, Senior Physicist,
University of Washington, Seattle, WA, January 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="70"></a><b>page 70 and 77:</b>
<br><font color="#000000"><i><font face="Times New Roman,Times">In diagrams
change </font></i><font face="Courier New,Courier"><font size=-1>basic_streamout</font></font><i><font face="Times New Roman,Times">
to </font></i></font><b><blink><font face="Courier New,Courier"><font color="#FF6666"><font size=-1>basic_streambuf</font></font></font></blink></b><i><font face="Times New Roman,Times">.</font></i>
<p><img SRC="page70.gif" NOSAVE height=242 width=322>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>students of an IOStreams seminar
held at SAP AG in St. Leon-Rot, Germany, April 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="73"></a><b>page73:</b>
<br><i>On that page we describe the difference between the base class
version of <tt>rdbuf() </tt>and the hiding version in the concrete stream
classes. The text says: </i>
<p>Mind the difference described in the preceding chapter between the base
class version of <tt>rdbuf() </tt>and the hiding version in the concrete
stream classes. The base class version returns the stream buffer object
referred to by the stream buffer pointer; the derived class version returns
a pointer to the embedded stream buffer object. After resetting of the
stream buffer pointer, both are different.
<p>Astute reader Robert Goddard comments: <font size=-1>The phrase "both
are different" is ambiguous: different from one another (true), or both
are different from their previous values (false)? I suggest the phrase
"the result of a call to the base class's rdbuf() has changed but the result
of a call to the concrete class's rdbuf() has not." Or, since you have
spelled it out elsewhere, you may choose to shorten it to "the results
of calling the two rdbuf() functions differ from one another."</font>
<p><i>Suggested reading of the section therefore is:</i>
<p>Mind the difference described in the preceding chapter between the base
class version of <tt>rdbuf() </tt>and the hiding version in the concrete
stream classes. The base class version returns the stream buffer object
referred to by the stream buffer pointer; the derived class version returns
a pointer to the embedded stream buffer object. After resetting of the
stream buffer pointer, <b><blink><font color="#FF6666">the results of calling
the two <tt>rdbuf()</tt> functions differ from one another.</font></blink></b>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Robert P. Goddard, Senior Physicist,
University of Washington, Seattle, WA, January 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="85"></a><b>page 85:</b>
<br><i>Suggested improvement:</i>
<p>Class <tt>basic_streambuf<class charT, class Traits></tt> is an abstract
base class in the sense that no instances of this class can be constructed.
Its constructor is protected and <b><blink><font color="#FF6666">hence
</font></blink></b>accessible
only to derived classes.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="89"></a><b>page 89 & 90:</b>
<br><i>Typos in various places: replace "exits" by "exists":</i>
<p><i>page 89:</i>
<br>If the put area <b><blink><font color="#FF6666">exists</font></blink></b>
and it is not already full, i.e. next_pointer != 0 and next_pointer <
end_pointer, then the character is put to the position the next_pointer
is referring to, and the next_pointer is incremented.
<p><i>page 90:</i>
<br> If the get area <b><blink><font color="#FF6666">exists</font></blink></b>
and characters have already been read, i.e. next_pointer != 0 and begin_pointer
< next_pointer, then a putback position is available.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Robert P. Goddard, Senior Physicist,
University of Washington, Seattle, WA, January 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="92"></a><b>page 92:</b>
<br><i><font face="Times New Roman,Times">The buffer in the diagram is
larger than intended. Correct the diagram to:</font></i>
<p><img SRC="page92.gif" NOSAVE height=305 width=497>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Vikram bir Singh, October 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="115"></a><b>page 115:</b>
<br><i>The code sample must be corrected to: </i>
<p><font face="Courier New,Courier"><font size=-1>template <class charT,
class Traits></font></font>
<br><font face="Courier New,Courier"><font size=-1>void foo(basic_streambuf<charT,Traits>*
sbuf)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{</font></font>
<br><font face="Courier New,Courier"><font size=-1> Traits::char_type
c;</font></font>
<br><font face="Courier New,Courier"><font size=-1> Traits::int_type
i;</font></font>
<br><font face="Courier New,Courier"><font size=-1> i = sbuf->sgetc();
// get the next value</font></font>
<br><font face="Courier New,Courier"><font size=-1>
// see whether its end-of-file</font></font>
<br><font face="Courier New,Courier"><font size=-1> if (!<b><blink><font color="#FF6666">Traits::</font></blink></b>eq_int_type(i,Traits::eof())) </font></font>
<br><font face="Courier New,Courier"><font size=-1>
// if not, convert it to a character</font></font>
<br><font face="Courier New,Courier"><font size=-1> { c = <b><blink><font color="#FF6666">Traits::</font></blink></b>to_char_type(i); </font></font>
<br><font face="Courier New,Courier"><font size=-1> ...
// pass on the character</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<br><font face="Courier New,Courier"><font size=-1>}</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Wolfgang Kaisers, Germany,
July 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="144"></a><b>page 144:</b>
<br><i>Must read: </i>
<p>Invocation of <tt>erase_event</tt> callback functions on calls to <tt>copyfmt()
</tt>is
useful because <tt>copyfmt()</tt> <b><blink><font color="#FF6666">overwrites</font></blink></b>
the original data members of the stream object.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="152"></a><b>page 152-155:</b>
<br><i>The references to section 3.1.4, Refined Inserters and Extractors,
is incorrect in various places. The following pages must be corrected: </i>
<p><i>page 152:</i>
<br>The example in section <b><blink><font color="#FF6666">3.1.4</font></blink></b>,
Refined Inserters and Extractors, demonstrates the correct use of sentries.
<p><i>page 154:</i>
<br>A concrete example is shown in section <b><blink><font color="#FF6666">3.1.4</font></blink></b>,
Refined Inserters and Extractors.
<p><i>page 155:</i>
<br>Some of these aspects are demonstrated in the example presented in
section <b><blink><font color="#FF6666">3.1.4</font></blink></b>, Refined
Inserters and Extractors.
<p><i>page 155:</i>
<br>The inserters and extractors presented in section <b><blink><font color="#FF6666">3.1.5</font></blink></b>,
Generic Inserters and Extractors, are another demonstration of the principle.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Mark Rodgers Cadenza
New Zealand Ltd, June 2000 and</font></font>
<br><font face="Trebuchet MS"><font size=-2>Wolfgang Kaisers, Germany,
July 2000 and</font></font>
<br><font face="Trebuchet MS"><font size=-2>Bernd Mohr / Research Centre
Juelich, ZAM, Germany, August 2000 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="156"></a><b>page 156:</b>
<br><i>Ignore the footnote on page 156. We initially had no intent to discuss
format control parameters, but decided later that the example would be
incomplete without it and added a section on format control (see section
3.1.4.3). For this reason the footnote is obsolete and should be
removed.</i>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Bernd Mohr / Research Centre
Juelich, ZAM, Germany, August 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="160"></a><b>page 160:</b>
<br><i>Part of the sample code for the inserter is incorrect because the
<tt>fill_n</tt>
algorithm does not return the advanced output itertor as we had assumed,
but returns void instead. The corresponding code must be corrected to: </i>
<p><font face="Courier New,Courier"><font size=-1>if (charToPad <= 0)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{</font></font>
<br><font face="Courier New,Courier"><font size=-1> sink =
copy(s.begin(), s.end(), sink);</font></font>
<br><font face="Courier New,Courier"><font size=-1>}</font></font>
<br><font face="Courier New,Courier"><font size=-1>else</font></font>
<br><font face="Courier New,Courier"><font size=-1>{</font></font>
<br><font face="Courier New,Courier"><font size=-1> if (os.flags()
& ios_base::left)</font></font>
<br><font face="Courier New,Courier"><font size=-1> {</font></font>
<br><font face="Courier New,Courier"><font size=-1>
sink = copy(s.begin(), s.end(), sink);</font></font>
<br><font face="Courier New,Courier"><font size=-1> <b><blink><font color="#FF6666">fill_n(sink,charToPad,os.fill());</font></blink></b></font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<br><font face="Courier New,Courier"><font size=-1> else</font></font>
<br><font face="Courier New,Courier"><font size=-1> {</font></font>
<br><font face="Courier New,Courier"><font size=-1> <b><blink><font color="#FF6666">fill_n(sink,charToPad,os.fill());</font></blink></b></font></font>
<br><font face="Courier New,Courier"><font size=-1>
sink = copy(s.begin(), s.end(), sink);</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<br><font face="Courier New,Courier"><font size=-1>}</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Wolfgang Kaisers, Germany,
July 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="161"></a><b>page 161:</b>
<br><i>The section below might be slightly misleading. We did not
mean to suggest that the C++ standard requires dates before January
1, 1970 to be unrepresentable.</i>
<p><tt>mktime()</tt> also flags date values that cannot be represented
in a <tt>tm</tt> structure, such as dates before January 1, 1970.
<p><i>The C standard states that a conforming implementation of the C library
is required to document its choice of range and precision of times representable
in time_t. In all implementations that we know of the valid range starts
with January 1, 1970. In other words, whether or not a date before January
1, 1970 can be represented is implementation-defined.</i>
<p><i>Suggested improvement: add a footnote.</i>
<p><tt>mktime()</tt> also flags date values that cannot be represented.<b><sup><blink><font color="#FF6666">*</font></blink></sup></b>
<p><b><blink><font color="#FF6666"><font size=-1><sup>*</sup> The range
of times representable in <tt>time_t</tt> is implementation-defined. In
many implementations of the C library dates before January 1, 1970 cannot
be represented. </font></font></blink></b>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="162"></a><b>page 162:</b>
<br><i>The sample code is a simplification of the truth: The leap-year
rule in <tt>date::valid()</tt> is a little off. For example, 1900 wasn't
a leap year and 2100 won't be. We were deliberately trying to keep the
algorithm simple, because the focus of this section is on error indication
in inserters and extractors rather than leap-year algorithms. </i>
<p><i>Suggested improvement: add a footnote.</i>
<p><font face="Courier New,Courier"><font size=-1> bool valid()
// check for sensible date; rejects nonsense like 32.12.1999</font></font><b><sup><blink><font color="#FF6666">*</font></blink></sup></b>
<br><font face="Courier New,Courier"><font size=-1> { </font></font>
<br><font face="Courier New,Courier"><font size=-1> ...</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<p><b><font color="#FF6666"><font size=-1><sup><blink>*</blink></sup> <blink>The
leap-year rule in <tt>date::valid()</tt> is simplified For example, 1900
wasn't a leap year and 2100 won't be.</blink></font></font></b>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="171"></a><b>page 171:</b>
<br><i>The sample code for the inserter is incorrect and must be corrected
to: </i>
<p><font face="Courier New,Courier"><font size=-1>template <class charT,
class Traits, <b><blink><font color="#FF6666">class Argument</font></blink></b>></font></font>
<br><font face="Courier New,Courier"><font size=-1>basic_ostream<charT,
Traits>& g_inserter </font></font>
<br><font face="Courier New,Courier"><font size=-1> (basic_ostream<charT,
Traits>& os, const Argument& <b><blink><font color="#FF6666">arg</font></blink></b>)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Ben Dorman, Ph.D.
Principal Programmer Analyst, Raytheon ITSS</font></font>
<br><font face="Trebuchet MS"><font size=-2>Laboratory for High Energy
Astrophysics, NASA/GSFC, Greenbelt MD, April 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="177"></a><b>page 177:</b>
<br><i>Three of the function pointer types on page 177 are incorrect and
must be corrected to: </i>
<p><font face="Courier New,Courier"><font size=-1>(2) basic_ios<charT,Traits>&
(*pf)(basic_ios<charT,Traits><b><blink><font color="#FF6666">&</font></blink></b>)</font></font>
<br><font face="Courier New,Courier"><font size=-1>(3) basic_istream<charT,Traits>&
(*pf)(basic_istream<charT,Traits><b><blink><font color="#FF6666">&</font></blink></b>)</font></font>
<br><font face="Courier New,Courier"><font size=-1>(4) basic_ostream<charT,Traits>&
(*pf)(basic_ostream<charT,Traits><b><blink><font color="#FF6666">&</font></blink></b>)</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Wayne Vucenic, Contract Programmer</font></font>
<br><font face="Trebuchet MS"><font size=-2>No Bugs Software, Cupertino,
California, June 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="180"></a><b>page 180:</b>
<br><i>The code samples contains some bugs. It must be corrected to:</i>
<p> <tt>class mendl {</tt>
<br><tt> public:</tt>
<br><tt> explicit mendl(unsigned int i) : i_(i) {}</tt>
<br><tt> private:</tt>
<br><tt> unsigned int i_;</tt>
<p><tt> template <class charT, class Traits></tt>
<br><tt> friend basic_ostream<charT,Traits>& operator<< </tt>
<br><tt> (basic_ostream<charT,Traits>& os, const
mendl& w)</tt>
<br><tt> { </tt>
<br><tt> // the manipulation: insert end-of-line
characters and flush</tt>
<br><tt> for (int i=0; i<<b><blink><font color="#FF6666">w.</font></blink></b>i_;
i++)</tt>
<br><tt> os.put(os.widen('\n')); </tt>
<br><tt> <b><blink><font color="#FF6666">return</font></blink></b>
os.flush();</tt>
<br><tt> }</tt>
<br><tt> };</tt>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Pete McEvoy, August 2000 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="188"></a><b>page 188:</b>
<br><i>The sample first code on this page has a couple of <tt>class</tt>
keyword that shouldn't be there. It should read: </i>
<p><font face="Courier New,Courier"><font size=-1> template <class
charT, class Traits, class Argument></font></font>
<br><font face="Courier New,Courier"><font size=-1> <b><blink><font color="#FF6666">basic_ostream<charT,Traits></font></blink></b>&
operator<< </font></font>
<br><font face="Courier New,Courier"><font size=-1> (<b><blink><font color="#FF6666">basic_ostream<charT,Traits></font></blink></b>&
os, </font></font>
<br><font face="Courier New,Courier"><font size=-1> const one_arg_manip_weh<Argument>&
oamw)</font></font>
<br><font face="Courier New,Courier"><font size=-1> {</font></font>
<br><font face="Courier New,Courier"><font size=-1> if(os.good())</font></font>
<br><font face="Courier New,Courier"><font size=-1>
do_manip(os,oamw);</font></font>
<br><font face="Courier New,Courier"><font size=-1> return os;</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Brian Chamberlain, July 2000</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="221"></a><b>page 221:</b>
<br><i>Freudian slip. The section must read:</i>
<p>The format string <tt>"%Y"</tt> produces the year <b><blink><font color="#FF6666">with</font></blink></b>
century as a decimal number, yet the output on the terminal is
<p><font face="Courier New,Courier"><font size=-1> Hello World, this
is ths year 1/1/00</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="222"></a><b>page 222:</b>
<br><i>The section must read:</i>
<p>Consequently, setting the format string to <b><tt><blink><font color="#FF6666">"%Y"</font></blink></tt></b>
has no effect.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="225"></a><b>page 225 - 248:</b>
<br><i>Throughout chapter 3.4 all member functions that return an <tt>int_type
</tt>are
incorrectly declared: the nested type <tt>int_type </tt> must be fully
qualified with the respective class scope when the member functions are
defined outside of the class scope. The following corrections must be made: </i>
<p><i>page 231:</i>
<br><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits ></font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">unbuffered_streambuf<charT,traits>::</font></blink></b>int_type</font></font>
<br><font face="Courier New,Courier"><font size=-1>unbuffered_streambuf<charT,traits>::overflow(int_type
c)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><i>page 232:</i>
<br><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits ></font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">unbuffered_streambuf<charT,traits>::</font></blink></b>int_type</font></font>
<br><font face="Courier New,Courier"><font size=-1>unbuffered_streambuf<charT,traits>::underflow()</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><i>page 232:</i>
<br><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits></font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">unbuffered_streambuf<charT,traits>::</font></blink></b>int_type</font></font>
<br><font face="Courier New,Courier"><font size=-1><font color="#000000">unbuffered_streambuf<charT,traits>::</font>uflow()</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits ></font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">unbuffered_streambuf<charT,traits>::</font></blink></b>int_type</font></font>
<br><font face="Courier New,Courier"><font size=-1>unbuffered_streambuf<charT,traits>::pbackfail(int_type
c)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><i>page 237:</i>
<br><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits></font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">outbuf<charT,traits>::</font></blink></b>int_type </font></font>
<br><font face="Courier New,Courier"><font size=-1>outbuf<charT,traits>::overflow
(int_type c)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><i>page 240:</i>
<br><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits></font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">inbuf<charT,traits>::</font></blink></b>int_type
inbuf<charT,traits>::underflow()</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><i>page 242:</i>
<br><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits></font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">inbuf<charT,traits>::</font></blink></b>int_type </font></font>
<br><font face="Courier New,Courier"><font size=-1>inbuf<charT,traits>::pbackfail(int_type
c)</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Mogens Hansen Software
Engineer at MAN B&W Diesel A/S in Copenhagen, Denmark and</font></font>
<br><font face="Trebuchet MS"><font size=-2>Allan Stokes Victoria
BC, Canada, June 2000 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="233"></a><b>page 233:</b>
<br><i>The signature of uflow() is incorrect and must be corrected to: </i>
<p><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits></font></font>
<br><font face="Courier New,Courier"><font size=-1><font color="#000000">unbuffered_streambuf<charT,
traits>::</font>int_type</font></font>
<br><font face="Courier New,Courier"><font size=-1><b><blink><font color="#FF6666">unbuffered_streambuf<charT,
traits>::</font></blink></b>uflow()</font></font>
<br><font face="Courier New,Courier"><font size=-1>{ ... }</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Mogens Hansen Software
Engineer</font></font>
<br><font face="Trebuchet MS"><font size=-2>MAN B&W Diesel A/S in Copenhagen,
Denmark, June 2000 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="240"></a><b>page 240:</b>
<br><i>In the code snippet in the middle of the page (implementation of
the constructor) we use an interger literal, although we've already defined
a symbolic name for the constant value. This is so ugly and should be corrected
to: </i>
<p><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits></font></font>
<br><font face="Courier New,Courier"><font size=-1>inbuf<charT,traits>::inbuf()</font></font>
<br><font face="Courier New,Courier"><font size=-1>{</font></font>
<br><font face="Courier New,Courier"><font size=-1> setg(buffer+<b><blink><font color="#FF6666">pbSize</font></blink></b>,
buffer+<b><blink><font color="#FF6666">pbSize</font></blink></b>, buffer+<b><blink><font color="#FF6666">pbSize</font></blink></b>);</font></font>
<br><font face="Courier New,Courier"><font size=-1>}</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Allan Stokes Victoria
BC, Canada, June 2000 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="241"></a><b>page 241:</b>
<br><i>Our implementation of inbuf::buffer_in() is copying overlapping
areas, which is undefined. We should be using memmove() instead.
The code must be corrected to:</i>
<p><font face="Courier New,Courier"><font size=-1>template <class charT,
class traits></font></font>
<br><font face="Courier New,Courier"><font size=-1>int inbuf<charT,traits>::buffer_in()</font></font>
<br><font face="Courier New,Courier"><font size=-1>{</font></font>
<br><font face="Courier New,Courier"><font size=-1> // determine
number of putback characters</font></font>
<br><font face="Courier New,Courier"><font size=-1> streamsize numPutbacks
= min(gptr() - eback(), pbSize);</font></font>
<p><font face="Courier New,Courier"><font size=-1> <b><blink><font color="#FF6666">memmove</font></blink></b>(buffer
+ (pbSize-numPutbacks) * sizeof(char_type),</font></font>
<br><font face="Courier New,Courier"><font size=-1>
gptr() - numPutbacks * sizeof(char_type),</font></font>
<br><font face="Courier New,Courier"><font size=-1>
numPutbacks * sizeof(char_type));</font></font>
<p><font face="Courier New,Courier"><font size=-1> int retval = buffer_from_device(buffer
+ pbSize * sizeof(char_type),</font></font>
<br><font face="Courier New,Courier"><font size=-1>
bufSize - pbSize);</font></font>
<br><font face="Courier New,Courier"><font size=-1> if (retval <=
0)</font></font>
<br><font face="Courier New,Courier"><font size=-1> {</font></font>
<br><font face="Courier New,Courier"><font size=-1> setg(0,0,0);</font></font>
<br><font face="Courier New,Courier"><font size=-1> return
-1;</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<br><font face="Courier New,Courier"><font size=-1> else</font></font>
<br><font face="Courier New,Courier"><font size=-1> {</font></font>
<br><font face="Courier New,Courier"><font size=-1> setg(buffer
+ pbSize - numPutbacks,</font></font>
<br><font face="Courier New,Courier"><font size=-1> buffer
+ pbSize, buffer + pbSize + retval);</font></font>
<br><font face="Courier New,Courier"><font size=-1> return
retval;</font></font>
<br><font face="Courier New,Courier"><font size=-1> }</font></font>
<br><font face="Courier New,Courier"><font size=-1>}</font></font>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="242"></a><b>page 242:</b>
<br><i>Typo. Section must read:</i>
<p>Again, the error handling in <b><tt><blink><font color="#FF6666">underflow()</font></blink></tt></b>is
oversimplified in that it always returns <tt>traits_type::eof()</tt> to
indicate failure, regardless of the source of the error.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="245"></a><b>page 245:</b>
<br><i>The description of showmanyc() could be more precise. Suggested
improvement:</i>
<p>The virtual member function <tt>showmanyc()</tt> (pronounced ess-how-many-see,
not show-manic) returns an estimation of the number of characters available
for input, or <tt>-1</tt>.<font color="#FF6666"> <b><blink>If the returned
value is positive, then at least the indicated number of characters can
be made available by one or more calls to <tt>underflow()</tt>. </blink></b></font>If
the operations returns <tt>-1</tt>, calls to <tt>underflow() </tt>and <tt>uflow()
</tt>will
fail. The intent is not only to know in advance that these calls will not
return <tt>traits_type::eof()</tt>, but that they will return immediately.
Or, to put it more simply, the purpose of this operation is to check if
characters are available on the external device, which can be read by <tt>underflow()
</tt>or
<tt>uflow()
</tt>without
waiting.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="255"></a><b>page 255:</b>
<br><i>The example of a Greek date format is slightly incorrect: The iota
used in the name of the day and the name of the month must be accented
using the Unicode character 03AF. <a href="greekDateFormat.html">Click
here</a> for the correct format using ISO-8859-7 character encoding.</i>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Klitos Kyriacou UK, March 2001 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="272"></a><b>page 272:</b>
<br><i>Typo in page. Should read:</i>
<p>The reference returned remains valid at least as long as any copy of
the containing locale exists. Section <b><blink><font color="#FF6666">7.3</font></blink></b>,
Memory Management of Facets in a Locale, explains why this is and how it
works.
<p><i>Typo in footnote. Should read:</i>
<p>4. The facet type <tt>money_put<char, string_inserter<char> >
</tt>is
an instantiation of the <tt>money_put</tt> template for an output iterator
other than the default, which is <tt>ostreambuf_iterator<charT>
</tt>and
was omitted from the list of template arguments in <b><tt><blink><font color="#FF6666">money_put<char></font></blink></tt></b>.
...
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Klaus Wittlich, Cologne Germany,
December 2000</font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001</font></font>
<br><font face="Trebuchet MS"><font size=-2>Steve Love, UK, April 2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="275"></a><b>page 275:</b>
<br><i>Typo in page. Should read:</i>
<p>To be more precise, we should say that in every locale there is one
representative of each standard facet family. Remember, we mentioned before,
at the beginning of chapter <b><blink><font color="#FF6666">5</font></blink></b>,
that facet types are organized in facet families, that is, hierarchies
of facet classes derived from each other.
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>James M. Stern,
ITG, Inc., Culver City, CA, April 2001 </font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="281"></a><b>page 281:</b>
<br><i>Typo in the code sample. Must read:</i>
<p><tt>template <class String></tt>
<br><tt>String* compare1toM (<b><blink><font color="#FF6666">locale</font></blink></b>
loc, String one, String* begin, String* end)</tt>
<br><tt>{</tt>
<br><tt> const collate<String::value_type>& collateFacet =</tt>
<br><tt>
use_facet< collate<String::value_type> >(loc);</tt>
<br><tt> String tmpOne = </tt>
<br><tt> collateFacet.transform(one.c_str(),one.c_str()+one.length());</tt>
<br><tt> for (; begin < end ; begin++)</tt>
<br><tt> {</tt>
<br><tt> String tmpMany = collateFacet.transform((*begin).c_str(),</tt>
<br><tt>
(*begin).c_str()+(*begin).length());</tt>
<br><tt> if (tmpOne == tmpMany)</tt>
<br><tt> return(begin);</tt>
<br><tt> }</tt>
<br><tt> return (end);</tt>
<br><tt>}</tt>
<p><font face="Trebuchet MS"><font size=-2>error found by: </font></font>
<br><font face="Trebuchet MS"><font size=-2>Norihisa Kitazawa, Japan, April
2001</font></font>
<br><img SRC="../Images/bar-small.gif" VSPACE=10 NOSAVE height=1 width=450>
<br><a NAME="284"></a><b>page 284:</b>