C The Complete Reference Herbert Schildt All Chapter Instant Download
C The Complete Reference Herbert Schildt All Chapter Instant Download
com
https://ebookname.com/product/c-the-complete-reference-
herbert-schildt/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/java-2-the-complete-reference-5th-
edition-herbert-schildt/
https://ebookname.com/product/herb-schildt-s-java-programming-
cookbook-1st-edition-herbert-schildt/
https://ebookname.com/product/the-art-of-java-1st-edition-
herbert-schildt/
https://ebookname.com/product/the-future-of-kurdistan-the-iraqi-
dilemma-1st-edition-kerim-yildiz/
Schools for All Kinds of Minds Boosting Student Success
by Embracing Learning Variation 1st Edition Mary-Dean
Barringer
https://ebookname.com/product/schools-for-all-kinds-of-minds-
boosting-student-success-by-embracing-learning-variation-1st-
edition-mary-dean-barringer/
https://ebookname.com/product/facing-cancer-and-the-fear-of-
death-a-psychoanalytic-perspective-on-treatment-1st-edition-
norman-straker-ed/
https://ebookname.com/product/bernard-shaw-and-the-bbc-1st-
edition-l-w-conolly/
https://ebookname.com/product/union-tactics-and-economic-change-
a-case-study-of-three-philadelphia-textile-unions-gladys-l-
palmer/
https://ebookname.com/product/seismic-amplitude-an-interpreter-s-
handbook-simm-r/
Identifying and Managing Project Risk Essential Tools
for Failure Proofing Your Project 3rd Edition Tom
Kendrick
https://ebookname.com/product/identifying-and-managing-project-
risk-essential-tools-for-failure-proofing-your-project-3rd-
edition-tom-kendrick/
C++:
The Complete Reference,
Fourth Edition
About the Author
Herbert Schildt is the world’s leading programming
author. He is an authority on the C, C++, Java, and C#
languages, and is a master Windows programmer. His
programming books have sold more than 3 million
copies worldwide and have been translated into all
major foreign languages. He is the author of numerous
bestsellers, including C++: The Complete Reference, C#:
The Complete Reference, Java 2: The Complete Reference,
C: The Complete Reference, C++ from the Ground Up,
C++: A Beginner’s Guide, C#: A Beginner’s Guide, and
Java 2: A Beginner’s Guide. Schildt holds a master’s
degree in computer science from the University of
Illinois. He can be reached at his consulting office at
(217) 586-4683.
Copyright © 2003 by The McGraw-Hill Companies. Click here for terms of use.
C++:
The Complete Reference,
Fourth Edition
Herbert Schildt
McGraw-Hill/Osborne
New York Chicago San Francisco
Lisbon London Madrid Mexico City
Milan New Delhi San Juan
Seoul Singapore Sydney Toronto
Copyright © 2003 by The McGraw-Hill Companies. All rights reserved. Manufactured in the United States of America. Except as per-
mitted under the United States Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any
means, or stored in a database or retrieval system, without the prior written permission of the publisher.
0-07-150239-4
The material in this eBook also appears in the print version of this title: 0-07-222680-3.
All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked
name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the
trademark. Where such designations appear in this book, they have been printed with initial caps.
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate
training programs. For more information, please contact George Hoare, Special Sales, at [email protected] or
(212) 904-4069.
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work.
Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one
copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, trans-
mit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent. You may use the
work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right to use the work may be
terminated if you fail to comply with these terms.
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO
THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK,
INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE,
AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WAR-
RANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill and its licensors do not warrant
or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free.
Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in
the work or for any damages resulting therefrom. McGraw-Hill has no responsibility for the content of any information accessed through
the work. Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, conse-
quential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibil-
ity of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in con-
tract, tort or otherwise.
DOI: 10.1036/0072226803
Professional
1 An Overview of C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4 Arrays and Null-Terminated Strings . . . . . . . . . . . . . . . . 89
5 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
6 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
7 Structures, Unions, Enumerations,
and User-Defined Types . . . . . . . . . . . . . . . . . . . . . . . . 161
8 C-Style Console I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
9 File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
10 The Preprocessor and Comments . . . . . . . . . . . . . . . . . . 237
Part II C++
v
vi C++: The Complete Reference
Contents
Introduction ............................................. xxix
Part I
The Foundation of C++: The C Subset
1 An Overview of C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Origins and History of C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
C Is a Middle-Level Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
C Is a Structured Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
C Is a Programmer’s Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Form of a C Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
The Library and Linking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Separate Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Understanding the .C and .CPP File Extensions . . . . . . . . . . . . . . . . 12
2 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
The Five Basic Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Modifying the Basic Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Identifier Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Where Variables Are Declared . . . . . . . . . . . . . . . . . . . . . . . . 18
Local Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
ix
x C++: The Complete Reference
Formal Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Global Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
The const and volatile Qualifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
const . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
volatile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Storage Class Specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
extern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
static Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
register Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Variable Initializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Hexadecimal and Octal Constants . . . . . . . . . . . . . . . . . . . . 33
String Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Backslash Character Constants . . . . . . . . . . . . . . . . . . . . . . . 33
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
The Assignment Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Type Conversion in Assignments . . . . . . . . . . . . . . . . . . . . . 35
Multiple Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Increment and Decrement . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Relational and Logical Operators . . . . . . . . . . . . . . . . . . . . . 40
Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
The ? Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
The & and * Pointer Operators . . . . . . . . . . . . . . . . . . . . . . . 48
The Compile-Time Operator sizeof . . . . . . . . . . . . . . . . . . . 50
The Comma Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
The Dot (.) and Arrow (−>) Operators . . . . . . . . . . . . . . . . . 51
The [ ] and ( ) Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Precedence Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Order of Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Type Conversion in Expressions . . . . . . . . . . . . . . . . . . . . . . 53
Casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Spacing and Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Compound Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3 Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
True and False in C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Selection Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Nested ifs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
The if-else-if Ladder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
The ? Alternative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
The Conditional Expression . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Contents xi
switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Nested switch Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Iteration Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
The for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
for Loop Variations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
The Infinite Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
for Loops with No Bodies . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
The while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
The do-while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Declaring Variables Within Selection and Iteration Statements . . . 81
Jump Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
The return Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
The goto Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The break Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The exit( ) Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
The continue Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Expression Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Block Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
5 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
What Are Pointers? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Pointer Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
The Pointer Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Pointer Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Pointer Assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Pointer Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Pointer Comparisons . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Pointers and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Arrays of Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Multiple Indirection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Initializing Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Pointers to Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
xii C++: The Complete Reference
6 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
The General Form of a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Scope Rules of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Function Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Call by Value, Call by Reference . . . . . . . . . . . . . . . . . . . . . . 139
Creating a Call by Reference . . . . . . . . . . . . . . . . . . . . . . . . . 140
Calling Functions with Arrays . . . . . . . . . . . . . . . . . . . . . . . 142
argc and argv—Arguments to main( ) . . . . . . . . . . . . . . . . . . . . . . . . 144
The return Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Returning from a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Returning Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Returning Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Functions of Type void . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
What Does main( ) Return? . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Function Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Standard Library Function Prototypes . . . . . . . . . . . . . . . . . 157
Declaring Variable-Length Parameter Lists . . . . . . . . . . . . . . . . . . . . 158
Old-Style Versus Modern FunctionParameter Declarations . . . . . . 158
Part II
C++
16 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
Base-Class Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Inheritance and protected Members . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Protected Base-Class Inheritance . . . . . . . . . . . . . . . . . . . . . . 424
Inheriting Multiple Base Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425
Constructors, Destructors, and Inheritance . . . . . . . . . . . . . . . . . . . . 426
When Constructors and Destructors Are Executed . . . . . . 426
Passing Parameters to Base-Class Constructors . . . . . . . . . 430
Granting Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 434
Virtual Base Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
18 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Generic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
A Function with Two Generic Types . . . . . . . . . . . . . . . . . . . 463
Explicitly Overloading a Generic Function . . . . . . . . . . . . . 463
Overloading a Function Template . . . . . . . . . . . . . . . . . . . . . 466
Using Standard Parameters with Template Functions . . . . 466
Generic Function Restrictions . . . . . . . . . . . . . . . . . . . . . . . . 467
Applying Generic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
A Generic Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 469
Compacting an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Generic Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
An Example with Two Generic Data Types . . . . . . . . . . . . . 476
Applying Template Classes: A Generic Array Class . . . . . 477
Using Non-Type Arguments with Generic Classes . . . . . . 479
Using Default Arguments with Template Classes . . . . . . . 481
Explicit Class Specializations . . . . . . . . . . . . . . . . . . . . . . . . . 483
xviii C++: The Complete Reference
Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
Other STL Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632
The Container Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
General Theory of Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 634
Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635
Accessing a Vector Through an Iterator . . . . . . . . . . . . . . . . 639
Inserting and Deleting Elements in a Vector . . . . . . . . . . . . 641
Storing Class Objects in a Vector . . . . . . . . . . . . . . . . . . . . . . 643
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645
Understanding end( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649
push_front( ) vs. push_back( ) . . . . . . . . . . . . . . . . . . . . . . . . 651
Sort a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
Merging One List with Another . . . . . . . . . . . . . . . . . . . . . . 653
Storing Class Objects in a List . . . . . . . . . . . . . . . . . . . . . . . . 655
Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 658
Storing Class Objects in a Map . . . . . . . . . . . . . . . . . . . . . . . 662
Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
Counting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664
Removing and Replacing Elements . . . . . . . . . . . . . . . . . . . 670
Reversing a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672
Transforming a Sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673
Using Function Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
Unary and Binary Function Objects . . . . . . . . . . . . . . . . . . . 675
Using the Built-in Function Objects . . . . . . . . . . . . . . . . . . . 675
Creating a Function Object . . . . . . . . . . . . . . . . . . . . . . . . . . . 678
Using Binders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 680
The string Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
Some string Member Functions . . . . . . . . . . . . . . . . . . . . . . . 687
Strings Are Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693
Putting Strings into Other Containers . . . . . . . . . . . . . . . . . 694
Final Thoughts on the STL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695
Part III
The Standard Function Library
fgets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
fopen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703
fprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705
fputc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705
fputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
fread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
freopen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706
fscanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707
fseek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707
fsetpos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
ftell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 708
fwrite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
getc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 709
getchar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
gets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
perror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 710
printf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 711
putc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
putchar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
puts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 714
remove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
rewind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
scanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 715
setbuf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
setvbuf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
sprintf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720
sscanf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720
tmpfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 720
tmpnam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
ungetc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 721
vprintf, vfprintf, and vsprintf . . . . . . . . . . . . . . . . . . . . . . . . 722
isxdigit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
memchr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
memcmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
memcpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
memmove . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 728
memset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
strcat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
strchr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 729
strcmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730
strcoll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730
strcpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
strcspn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
strerror . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
strlen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 731
strncat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
strncmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732
strncpy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
strpbrk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
strrchr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733
strspn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734
strstr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734
strtok . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 734
strxfrm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
tolower . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
toupper . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 735
rand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770
setjmp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770
signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 770
srand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771
strtod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 771
strtol . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772
strtoul . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 772
system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773
va_arg, va_start, and va_end . . . . . . . . . . . . . . . . . . . . . . . . . 773
wcstombs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774
wctomb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 774
Part IV
The Standard C++ Class Library
flush . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 797
fstream, ifstream, and ofstream . . . . . . . . . . . . . . . . . . . . . . . 797
gcount . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 798
getline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 799
good . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
ignore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 800
peek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 801
precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
put . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
putback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
rdstate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 802
read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
readsome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803
seekg and seekp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 804
setf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
setstate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 805
str . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806
stringstream, istringstream, ostringstream . . . . . . . . . . . . . 806
sync_with_stdio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 807
tellg and tellp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808
unsetf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808
width . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808
write . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 809
copy_backward . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841
count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 841
count_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842
equal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842
equal_range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 842
fill and fill_n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843
find . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843
find_end . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843
find_first_of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843
find_if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844
for_each . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844
generate and generate_n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 844
includes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845
inplace_merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845
iter_swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 845
lexicographical_compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846
lower_bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846
make_heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846
max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
max_element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 847
min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
min_element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
mismatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 848
next_permutation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
nth_element . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
partial_sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 849
partial_sort_copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850
partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850
pop_heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 850
prev_permutation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851
push_heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851
random_shuffle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 851
remove, remove_if, remove_copy, and remove_copy_if . 852
replace, replace_copy, replace_if, and replace_copy_if . . . 852
reverse and reverse_copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
rotate and rotate_copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853
search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854
search_n . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854
set_difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 854
set_intersection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855
set_symmetric_difference . . . . . . . . . . . . . . . . . . . . . . . . . . . . 855
set_union . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856
sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856
sort_heap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 856
Contents xxvii
stable_partition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857
stable_sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857
swap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 857
swap_ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
unique and unique_copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . 858
upper_bound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 859
Part V
Applying C++
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1009
f there is one language that defines modern programming, it is C++. Its syntax,
I style, and philosophy have set the standard by which all other languages are
judged. Furthermore, C++ is the universal language of programming. When an
algorithm or technique is described, it is usually done so using the C++ syntax. The
long-term success of C++ has also left a lasting impression on computer language
development. For example, both Java and C# are descended from C++. Frankly, to be
a professional programmer implies proficiency in C++. It is the one language that no
programmer can afford to ignore.
This is the fourth edition of C++: The Complete Reference. It fully describes and
demonstrates the keywords, syntax, functions, classes, and features that define the C++
language. More specifically, this book fully describes Standard C++. This is the version
of C++ defined by the ANSI/ISO Standard for C++ and it is the version of C++ that is
supported by all major compilers, including Microsoft’s Visual C++ and Borland’s C++
Builder. Thus, the information in this book is applicable to all modern programming
environments.
In the time that has passed since the previous edition of this book, there have
been no changes to the C++ language. There have, however, been big changes to the
computing environment. For example, a new standard for C, called C99, was created,
Java became the dominant language for Web programming, the .NET Framework was
xxix
Copyright © 2003 by The McGraw-Hill Companies. Click here for terms of use.
xxx C++: The Complete Reference
released, and C# was invented. Through all the changes of the past few years, one thing
has remained constant: the staying power of C++. C++ has been, is, and will remain the
preeminent language for the development of high-performance software well into the
foreseeable future.
What’s Inside
This books covers in detail all aspects of the C++ language, including its foundation, C.
The book is divided into these five parts:
experienced C programmer can simply turn to the sections of this book that cover the
C++-specific features.
Part Two discusses in detail the features that move beyond the C foundation and
define the C++ language These include its object-oriented features such as classes,
constructors, destructors, RTTI, and templates. Thus, Part Two covers those constructs
that “make C++, C++.”
Part Three describes the standard function library and Part Four examines the
standard class library, including the STL (Standard Template Library). Part Five
shows two practical examples of applying C++ and object-oriented programming.
If you want to learn about the C language, which is the foundation of all modern
programming, then the following titles will be of interest.
This book divides its description of the C++ language into two parts.
Part One discusses the C-like features of C++. This is commonly
referred to as the C subset of C++. Part Two describes those features
specific to C++. Together, these parts describe the entire C++ language.
Copyright © 2003 by The McGraw-Hill Companies. Click here for terms of use.
Other documents randomly have
different content
wurde, war geradezu kläglich. Nun aber macht sich eine Bewegung
bemerklich, die erkennen läßt, daß man bestrebt ist, „den Kindern
das Beste“ zu bieten. Und hier haben nun eine Anzahl von
Verlegern, vor allem die Wigands, im Verein mit unserem Künstler
mit sicherer und glücklichster Hand eingegriffen und wirklich wie im
Sprunge Versäumtes nachzuholen sich bemüht. Ihr Bestreben war
aber auch vom schönsten Erfolg gekrönt, die Bücher mit Bildern von
unserem Ludwig Richter wurden von alt und jung mit Jubel
aufgenommen.
Abb. 71. Z u D e r G e i z h a l s u n d s e i n
N a c h b a r.
Spinnstubengeschichten von Horn. 1855. (Zu Seite
61.)
Abb. 72. Z u Z w e i g e h o l z t e O h r f e i g e n .
Spinnstubengeschichten von Horn. 1856. (Zu Seite
61.)
Abb. 73. Zu D e r S c h l e i c h e r .
Spinnstubengeschichten von Horn.
1856. (Zu Seite 61.)
Abb. 74. Zu J ö r j a k o b . Spinnstubengeschichten von Horn.
1860. (Zu Seite 62.)