ebook img

C++: The Complete Reference PDF

1041 Pages·1998·8.769 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview C++: The Complete Reference

C++: The Complete Reference Third Edition About the Author… HerbSchildtistheleadingauthorityonCand C++andabest-sellingauthorwhosebooks havesoldmorethan1.5millioncopies.His acclaimedCandC++booksincludeTeach YourselfC,C++fromtheGroundUp,Teach YourselfC++,C++:TheCompleteReference, BorlandC++:TheCompleteReference,andC++ Programmer'sReferencetonameafew. C++: The Complete Reference Third Edition Herbert Schildt OsborneMcGraw-Hill Berkeley NewYork St.Louis SanFrancisco Auckland Bogotá Hamburg London Madrid MexicoCity Milan Montreal NewDelhi PanamaCity Paris SãoPaulo Singapore Sydney Tokyo Toronto abc McGraw-Hill Copyright ©1998 by McGraw-Hill Companies. All rights reserved. Manufactured in the United States of America. Except as permitted 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-213293-0 The material in this eBook also appears in the print version of this title: 0-07-882476-1 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 train- ing programs. For more information, please contact George Hoare, Special Sales, at [email protected] or (212) 904- 4069. TERMSOF 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, transmit, 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-HILLAND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS TO THE ACCURACY, ADEQUACYOR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANYINFORMATION THATCAN BE ACCESSED THROUGH THE WORK VIAHYPERLINK OR OTHERWISE, AND EXPRESSLYDISCLAIM ANYWARRANTY, EXPRESS OR IMPLIED, INCLUDING BUTNOTLIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITYOR FITNESS FOR APARTICULAR 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, spe- cial, punitive, consequential 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 possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises in contract, tort or otherwise. DOI: 10.1036/0072132930 Contents at a Glance Part I The Foundation of C++: The C Subset 1 AnOverviewofC ................................ 3 2 Expressions ...................................... 13 3 Statements ....................................... 57 4 ArraysandNull-Terminated Strings ................ 89 5 Pointers ......................................... 113 6 Functions ........................................ 137 7 Structures,Unions,Enumerations,andUser- Defined Types .................................. 161 8 C-StyleConsoleI/O .............................. 187 9 FileI/O ......................................... 211 10 ThePreprocessorandComments ................... 237 Part II C++ 11 AnOverviewofC++ ............................. 255 12 ClassesandObjects ................................ 289 13 Arrays,Pointers,Referencesand theDynamic AllocationOperators ........................... 327 14 FunctionOverloading,CopyConstructors, andDefaultArguments ........................ 361 15 OperatorOverloading ............................ 385 v vi C++: The Complete Reference 16 Inheritance ...................................... 419 17 Virtual FunctionsandPolymorphism .............. 445 18 Templates ...................................... 461 19 ExceptionHandling .............................. 489 20 C++I/O System Basics ........................... 511 21 C++File I/O ..................................... 541 22 Run-Time TypeIDandtheCastingOperators ........ 569 23 Namespaces,ConversionFunctions,and Other AdvancedTopics ............................... 593 24 Introducing theStandardTemplateLibrary .......... 625 Part III The Standard Function Library 25 TheC-BasedI/OFunctions ........................ 695 26 TheStringandCharacterFunctions ................. 719 27 TheMathematicalFunctions ....................... 733 28 Time,Date,andLocalizationFunctions .............. 743 29 TheDynamicAllocationFunctions .................. 753 30 UtilityFunctions .................................. 757 31 TheWide-CharacterFunctions ..................... 771 Part IV The Standard C++ Class Library 32 TheStandardC++ I/OClasses ..................... 783 33 TheSTLContainerClasses ......................... 807 34 TheSTLAlgorithms ............................... 835 35 STLIterators,Allocators,and FunctionObjects ....... 857 36 TheStringClass .................................. 877 37 TheNumericClasses .............................. 893 38 ExceptionHandlingandMiscellaneousClasses ....... 921 Part V Applying C++ 39 Integrating New Classes:ACustom StringClass ...... 931 40 AnObject-OrientedExpression Parser ............... 959 Index ............................................ 995 Contents Preface.................................................... xxix PartI TheFoundation ofC++:The CSubset 1 AnOverviewofC ............................... 3 TheOriginsofC ........................................... 4 CIsaMiddle-LevelLanguage ............................... 4 CIsaStructuredLanguage ................................. 6 CIsaProgrammer'sLanguage .............................. 8 TheFormofaCProgram ................................... 9 TheLibraryandLinking .................................... 10 SeparateCompilation ...................................... 12 Understandingthe.Cand.CPPFileExtensions ................ 12 2 Expressions ..................................... 13 TheFiveBasicDataTypes .................................. 14 vii viii C++: The Complete Reference ModifyingtheBasicTypes .................................. 15 IdentifierNames .......................................... 16 Variables ................................................. 17 WhereVariablesAreDeclared ....................... 17 LocalVariables ..................................... 17 FormalParameters ................................. 21 GlobalVariables .................................... 21 AccessModifiers .......................................... 23 const .............................................. 23 volatile ............................................ 24 StorageClassSpecifiers ..................................... 25 extern ............................................. 25 staticVariables ..................................... 27 registerVariables ................................... 29 VariableInitializations ..................................... 31 Constants ................................................. 31 HexadecimalandOctalConstants .................... 32 StringConstants ................................... 33 BackslashCharacterConstants ....................... 33 Operators ................................................. 34 TheAssignmentOperator ........................... 34 TypeConversioninAssignments ..................... 35 MultipleAssignments ............................... 36 ArithmeticOperators ............................... 37 IncrementandDecrement ........................... 37 RelationalandLogicalOperators ..................... 39 BitwiseOperators .................................. 42 The?Operator ..................................... 47 The&and*PointerOperators ....................... 47 TheCompile-TimeOperatorsizeof ................... 49 TheCommaOperator ............................... 50 TheDot(.)andArrow(−>)Operators ................. 51 The[]and()Operators ............................. 51 PrecedenceSummary ............................... 52 Expressions ............................................... 53 OrderofEvaluation ................................. 53 TypeConversioninExpressions ...................... 53 Casts ............................................. 54 SpacingandParentheses ............................ 55 ShorthandAssignments .................................... 56 3 Statements ...................................... 57 TrueandFalseinCandC++ ................................ 58 Contents ix SelectionStatements ....................................... 59 if ................................................. 59 Nestedifs ......................................... 60 Theif-else-ifLadder ................................ 62 The?Alternative ................................... 63 TheConditionalExpression .......................... 66 switch ............................................ 67 NestedswitchStatements ........................... 70 IterationStatements ........................................ 70 TheforLoop ....................................... 70 forLoopVariations ................................. 72 TheInfiniteLoop ................................... 76 forLoopswithNoBodies ........................... 77 ThewhileLoop .................................... 77 Thedo-whileLoop ................................. 79 DeclaringVariableswithinSelectionandIterationStatements ... 81 JumpStatements .......................................... 82 ThereturnStatement ................................ 82 ThegotoStatement ................................. 83 ThebreakStatement ................................ 83 Theexit()Function ................................. 85 ThecontinueStatement ............................. 86 ExpressionStatements ..................................... 88 BlockStatements .......................................... 88 4 ArraysandNull-Terminated Strings ............... 89 Single-DimensionArrays ................................... 90 GeneratingaPointertoanArray ............................ 92 PassingSingle-DimensionArraystoFunctions ................ 92 Null-TerminatedStrings .................................... 94 Two-DimensionalArrays ................................... 96 ArraysofStrings ................................... 100 MultidimensionalArrays ................................... 101 IndexingPointers .......................................... 102 ArrayInitialization ........................................ 105 UnsizedArrayInitializations ......................... 106 ATic-Tac-ToeExample ..................................... 108 5 Pointers ........................................ 113 WhatArePointers? ........................................ 114 PointerVariables .......................................... 115 ThePointerOperators ...................................... 115 PointerExpressions ........................................ 116

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.