C++完全参考手册(第4版影印版)

C++完全参考手册(第4版影印版)
作 者: Herbert Schildt
出版社: 清华大学出版社
丛编项: 大学计算机教育国外著名教材系列
版权说明: 本书为出版图书,暂不支持在线阅读,请支持正版图书
标 签: C++
ISBN 出版时间 包装 开本 页数 字数
未知 暂无 暂无 未知 0 暂无

作者简介

  作者:HerbertSchildtHerbertSchildt,是世界顶级程序设计大师,全球顶尖编程图书作者之一。他是C、C++、Java和C#编程语言的权威,也是Windows编程方面的专家。拥有伊利诺斯大学的计算机科学硕士学位。他的编程书籍在世界范围内的销量已经超过3000000册,并被翻译成多种语言流传于世。Java实用教程(第3版)>>更多作品

内容简介

《C++完全参考手册》作者Herbert Schildt是程序设计语言的大师,其著作涉及C、C++、Java和C# 等语言。《C++完全参考手册》以一种清晰而易懂的方式,全面介绍了C++语言的各个方面,如关键字、语法、函数、类和库,以及一些C++的高级特性,如重载、继承、虚拟函数、命名空间、模板、RTTI(运行时类型信息)以及STL(标准模板库)等。读者不仅可以从《C++完全参考手册》中学习到程序设计所需的语言知识,而且还可了解如何进行程序设计。《C++完全参考手册》适合作为C++语言的教学用书。《C++完全参考手册》介绍的内容适用于所有现代编程环境,适合于各种水平的C++程序设计人员,既可以作为帮助初学者解答特定问题的参考指南,也可以让C++编程高手从中发现许多有用功能的深入介绍。

图书目录

Part I The Foundation of C++: The C Subset

1 An Overview of C

The Origins and History of C

C Is a Middle-Level Language

C Is a Structured Language

C Is a Programmer's Language

The Form of a C Program

The Library and Linking

Separate Compilation

Understanding the .C and .CPP File Extensions.

2 Expressions

The Five Basic Data Types

Modifying the Basic Types

Identifier Names

Variables

Where Variables Are Declared

Local Variables

Formal Parameters

Global Variables

The const and volatile Qualifiers

const

volatile

Storage Class Specifiers

extern

static Variables

register Variables

Variable Initializations

Constants

Hexadecimal and Octal Constants

String Constants

Backslash Character Constants

Operators

The Assignment Operator

Type Conversion in Assignments

Multiple Assignments

Arithmetic Operators

Increment and Decrement

Relational and Logical Operators

Bitwise Operators

The ? Operator

The & and * Pointer Operators

The Compile-Time Operator sizeof

The Comma Operator

The Dot (.) and Arrow (->) Operators

The [ ] and ( ) Operators

Precedence Summary

Expressions

Order of Evaluation

Type Conversion in Expressions

Casts

Spacing and Parentheses

Compound Assignments

3 Statements

True and False in C and C++

Selection Statements

if

Nested ifs

The if-else-if Ladder

The ? Alternative

The Conditional Expression

switch

Nested switch Statements

Iteration Statements

The for Loop

for Loop Variations

The Infinite Loop

for Loops with No Bodies

The while Loop

The do-while Loop

Declaring Variables Within Selection and Iteration Statements

Jump Statements

The return Statement

The goto Statement

The break Statement

The exit( ) Function

The continue Statement

Expression Statements

Block Statements

4 Arrays and Null-Terminated Strings

Single-Dimension Arrays

Generating a Pointer to an Array

Passing Single-Dimension Arrays to Functions

Null-Terminated Strings

Two-Dimensional Arrays

Arrays of Strings

Multidimensional Arrays

Indexing Pointers

Array Initialization

Unsized Array Initializations

A Tic-Tac-Toe Example

5 Pointers

What Are Pointers?

Pointer Variables

The Pointer Operators

Pointer Expressions

Pointer Assignments

Pointer Arithmetic

Pointer Comparisons

Pointers and Arrays

Arrays of Pointers

Multiple Indirection

Initializing Pointers

Pointers to Functions

C's Dynamic Allocation Functions

Problems with Pointers

6 Functions

The General Form of a Function

Scope Rules of Functions

Function Arguments

Call by Value, Call by Reference

Creating a Call by Reference

Calling Functions with Arrays

argc and argv--Arguments to main( )

The return Statement

Returning from a Function

Returning Values

Returning Pointers

Functions of Type void

What Does main( ) Return?

Recursion

Function Prototypes

Standard Library Function Prototypes

Declaring Variable-Length Parameter Lists

Old-Style Versus Modern FunctionParameter Declarations ...

7 Structures, Unions, Enumerations,

and User-Defined Types

Structures

Accessing Structure Members

Structure Assignments

Arrays of Structures

Passing Structures to Functions

Passing Structure Members to Functions

Passing Entire Structures to Functions

Structure Pointers

Declaring a Structure Pointer

Using Structure Pointers

Arrays and Structures Within Structures

Bit-Fields

Unions

Enumerations

Using sizeof to Ensure Portability

typedef

8 C-Style Console I/O

An Important Application Note

Reading and Writing Characters

A Problem with getchar( )

Alternatives to getchar( )

Reading and Writing Strings

Formatted Console I/O

printf( )

Printing Characters

Printing Numbers

Displaying an Address

The %n Specifier

Format Modifiers

The Minimum Field Width Specifier

The Precision Specifier

Justifying Output

Handling Other Data Types

The * and # Modifiers

scanf( )

Format Specifiers

Inputting Numbers

Inputting Unsigned Integers

Reading Individual Characters Using scanf( )

Reading Strings

Inputting an Address

The %n Specifier

Using a Scanset

Discarding Unwanted White Space

Non-White-Space Characters in the Control String

You Must Pass scanf( ) Addresses

Format Modifiers

Suppressing Input

9 File I/O

C Versus C++ File I/O

Streams and Files

Streams

Text Streams

Binary Streams

Files

File System Basics

The File Pointer

Opening a File

Closing a File

Writing a Character

Reading a Character

Using fopen(), getc(), putc(), and fclose( )

Using feof( )

Working with Strings: fputs( ) and fgets( )

rewind( )

ferror( )

Erasing Files

Flushing a Stream

fread( ) and fwrite( )

Using fread( ) and fwrite( )

fseek( ) and Random-Access I/O

fprintf( ) and fscanf( )

The Standard Streams

The Console I/0 Connection

Using freopen( )to Redirect the Standard Streams

10 The Preprocessor and Comments

The Preprocessor

#define

Defining Function-like Macros

#error

#include

Conditional Compilation Directives

#if, #else, #elif, and #endif

#ifdef and #ifndef

#undef

Using defined

#line

#pragma

The # and ## Preprocessor Operators

Predefined Macro Names

Comments

Single-Line Comments

Part II C++

11 An Overview of C++

The Origins of C++

What Is Object-Oriented Programming?

Encapsulation

Polymorphism

Inheritance

Some C++ Fundamentals

A Sample C++ Program

A Closer Look at the I/O Operators

Declaring Local Variables

No Default to int

The bool Data Type

Old-Style vs. Modern C++

The New C++ Headers

Namespaces

Working with an Old Compiler

Introducing C++ Classes

Function Overloading

Operator Overloading

Inheritance

Constructors and Destructors

The C++ Keywords

The General Form of a C++ Program

12 Classes and Objects

Classes

Structures and Classes Are Related

Unions and Classes Are Related

Anonymous Unions

Friend Functions

Friend Classes

Inline Functions

Defining Inline Functions Within a Class

Parameterized Constructors

Constructors with One Parameter: A Special Case .,

Static Class Members

Static Data Members

Static Member Functions

When Constructors and Destructors Are Executed

The Scope Resolution Operator

Nested Classes

Local Classes

Passing Objects to Functions

Returning Objects

Object Assignment

13 Arrays, Pointers, References, and the Dynamic

Allocation Operators

Arrays of Objects

Creating Initialized vs. Uninitialized Arrays

Pointers to Objects

Type Checking C++ Pointers

The this Pointer

Pointers to Derived Types

Pointers to Class Members

References

Reference Parameters

Passing References to Objects-

Returning References

Independent References

References to Derived Types

Restrictions to References

A Matter of Style

C++'s Dynamic Allocation Operators

Initializing Allocated Memory

Allocating Arrays

Allocating Objects

The nothrow Alternative

The Placement Form of new

14 Function Overloading, Copy Constructors,

and Default Arguments

Function Overloading

Overloading Constructors

Overloading a Constructor to Gain Flexibility

Allowing Both Initialized and Uninitialized Objects

Copy Constructors

Finding the Address of an Overloaded Function

The overload Anachronism

Default Function Arguments

Default Arguments vs. Overloading

Using Default Arguments Correctly

Function Overloading and Ambiguity

15 Operator Overloading

Creating a Member Operator Function

Creating Prefix and Postfix Forms

of the Increment and Decrement Operators

Overloading the Shorthand Operators

Operator Overloading Restrictions

Operator Overloading Using a Friend Function

Using a Friend to Overload ++ or --

Friend Operator Functions Add Flexibility

Overloading new and delete

Overloading new and delete for Arrays

Overloading the nothrow Version of new and delete

Overloading Some Special Operators

Overloading [ ]

Overloading ( )

Overloading ->

Overloading the Comma Operator

16 Inheritance

Base-Class Access Control

Inheritance and protected Members

Protected Base-Class Inheritance

Inheriting Multiple Base Classes

Constructors, Destructors, and Inheritance

When Constructors and Destructors Are Executed

Passing Parameters to Base-Class Constructors

Granting Access

Virtual Base Classes

17 Virtual Functions and Polymorphism

Virtual Functions

Calling a Virtual Function Through a Base

Class Reference

The Virtual Attribute Is Inherited

Virtual Functions Are Hierarchical

Pure Virtual Functions

Abstract Classes

Using Virtual Functions

Early vs. Late Binding

18 Templates

Generic Functions

A Function with Two Generic Types

Explicitly Overloading a Generic Function

Overloading a Function Template

Using Standard Parameters with Template Functions

Generic Function Restrictions

Applying Generic Functions

A Generic Sort

Compacting an Array

Generic Classes

An Example with Two Generic Data Types

Applying Template Classes: A Generic Array Class

Using Non-Type Arguments with Generic Classes

Using Default Arguments with Template Classes

Explicit Class Specializations

The typename and export Keywords

The Power of Templates

19 Exception Handling

Exception Handling Fundamentals

Catching Class Types

Using Multiple catch Statements

Handling Derived-Class Exceptions

Exception Handling Options

Catching All Exceptions

Restricting Exceptions

Rethrowing an Exception

Understanding terminate( ) and unexpected( )

Setting the Terminate and Unexpected Handlers

The uncaught_exception( ) Function

The exception and bad_exception Classes

Applying Exception Handling

20 The C++ I/O System Basics

Old vs. Modern C++ I/O

C++ Streams

The C++ Stream Classes

C++'s Predefined Streams

Formatted I/O

Formatting Using the ios Members

Setting the Format Flags

Clearing Format Flags

An Overloaded Form of setf( )

Examining the Formatting Flags

Setting All Flags

Using width(), precision(), and fill( )

Using Manipulators to Format I/O

Overloading << and >>

Creating Your Own Inserters

Creating Your Own Extractors

Creating Your Own Manipulator Functions

21 C++ File I/O

and the File Classes

Opening and Closing a File

Reading and Writing Text Files

Unformatted and Binary I/O

Characters vs. Bytes

put( ) and get( )

read( ) and write( )

More get( ) Functions

getline( )

Detecting EOF

The ignore( ) Function

peek( ) and putback( )

flush( )

Random Access

Obtaining the Current File Position

I/O Status

Customized I/O and Files

22 Run-Time Type ID and the Casting Operators

Run-Time Type Identification (RTTI)

The Casting Operators

dynamic_cast

23 Namespaces, Conversion Functions,

and Other Advanced Topics

Namespaces

Namespace Fundamentals

using

Unnamed Namespaces

Some Namespace Options

The std Namespace

Creating Conversion Functions

const Member Functions and mutable

Volatile Member Functions

Explicit Constructors

The Member Initialization Syntax

Using the asm Keyword

Linkage Specification

Array-Based I/O

The Array-Based Classes

Creating an Array-Based Output Stream

Using an Array as Input

Input/Output Array-Based Streams

Using Dynamic Arrays

Using Binary I/O with Array-Based Streams

Summarizing the Differences Between C and C++

24 Introducing the Standard Template Library

An Overview of the STL

Containers

Algorithms

Iterators

Other STL Elements

The Container Classes

General Theory of Operation

Vectors

Accessing a Vector Through an Iterator

Inserting and Deleting Elements in a Vector

Storing Class Objects in a Vector

Lists

Understanding end( )

push_front( ) vs. push_back( )

Sort a List

Merging One List with Another

Storing Class Objects in a List

Maps

Storing Class Objects in a Map

Algorithms

Counting

Removing and Replacing Elements

Reversing a Sequence

Transforming a Sequence

Using Function Objects

Unary and Binary Function Objects

Using the Built-in Function Objects

Creating a Function Object

Using Binders

The string Class

Some string Member Functions

Strings Are Containers

Putting Strings into Other Containers

Final Thoughts on the STL

Part III The Standard Function Library

The C-Based I/O Functions

clearerr

fclose

feof

ferror

fflush

fgetc

fgetpos

fgets

fopen

fprintf

fputc

fputs

fread

freopen

fscanf

fseek

fsetpos

ftell

fwrite

getc

getchar

gets

perror

printf

putc

putchar

puts

remove

rename

rewind

scanf

setbuf

setvbuf

sprintf

sscanf

tmpfile

tmpnam

ungetc

vprintf, vfprintf, and vsprintf

26 The String and Character Functions

isalnum

isalpha

iscntrl

isdigit

isgraph

islower

isprint

ispunct

lsspace

lsupper

isxdigit

memchr

memcmp

memcpy

memmove

memset

strcat

strchr

strcmp

strcoll

strcpy

strcspn

strerror

strlen

strncat

strncmp

strncpy

strpbrk

strrchr

strspn

strstr

strtok

strxfrm

tolower

toupper

27 The Mathematical Functions

aCOS

asin

atan

atan2

ceil

COS

cosh

exp

fabs

floor

fmod

frexp

ldexp

log

loglO

modf

pow

sin

sinh

sqrt

tan

tanh

28 Time, Date, and Localization Functions

asctime

clock

ctime

difftime

gmtime

localeconv

localtime

mktime

setlocale

strftime

time

29 The Dynamic Allocation Functions

calloc

free

malloc

realloc

30 Utility Functions

abort

abs

assert

atexit

atof

atoi

atol

bsearch

div

exit

getenv

labs

ldiv

longjmp

mblen

mbstowcs

mbtowc

qsort

raise

rand

setjmp

signal

srand

strtod

strtol

strtoul

system

va_arg, va_start, and va_end

wcstombs

wctomb

31 The Wide-Character Functions

The Wide-Character Classification Functions

The Wide-Character I/O Functions

The Wide-Character String Functions

Wide-Character String Conversion Functions

Wide-Character Array Functions

Multibyte/Wide-Character Conversion Functions

Part IV The Standard C++ Class Library

32 The Standard C++ I/O Classes

The I/O Classes

The I / O Headers

The Format Flags and I/O Manipulators

Several Data Types

The streamsize and streamoff Types

The streampos and wstreampos Types

The pos_type and off_type Types

The openmode Type

The iostate Type

The seekdir Type

The failure Class

Overload << and >> Operators

The General-Purpose I/O Functions

bad

clear

eof

exceptions

fail

fill

flags

flush

fstream, ifstream, and ofstream

gcount

get

getline

good

ignore

open

peek

precision

put

putback

rdstate

read

readsome

seekg and seekp

setf

setstate

str

stringstream, istringstrearn, ostringstream .

sync_with_stdio

tellg and tellp

unsetf

width

write

33 The STL Container Classes

The Container Classes

bitset

deque

list

map

multimap

multiset

queue

priority_queue

set

stack

vector

34 The STL Algorithms

adjacent_find

binary_search

copy

copy_backward

count

count_if

equal

equal_range

fill and fill_n

find

find_end

find_first_of

find_if

for_each

generate and generate_n

includes

inplace_merge

iter_swap

lexicographical_compare

lower bound

make_heap

max

max_element

merge

min

rain_element

mismatch

next_permutation

nth_element

partial_sort

partial_sort_copy

partition

pop_heap

prev permutation

push_heap

random_shuffle

remove,remove_if,remove_copy,and remove_copy_if

replace, replace_copy, replace_if, and replace_copy_if

reverse and reverse_copy

rotate and rotate_copy

search

search_n

set difference

set_intersection

set_symmetric_difference

set_union

sort

sort_heap

stable_partition

stable_sort

swap

swap_ranges

transform

unique and unique_copy

upper_bound

35 STL Iterators, Allocators, and Function Objects

Iterators

The Basic Iterator Types

The Low-Level Iterator Classes

The Predefined Iterators

Two Iterator Functions

Function Objects

Function Objects

Binders

Negators

Adaptors

Allocators

36 The String Class

The basic_string Class

The char_traits Class

37 The Numeric Classes

The complex Class

The valarray Class

The slice and gslice Classes

The Helper Classes

The Numeric Algorithms

accumulate

adjacent_difference

inner_product

partial_sum

38 Exception Handling and Miscellaneous Classes

Exceptions

auto_ptr

The pair Class

Localization

Other Classes of Interest

Part V Applying C++

39 Integrating New Classes: A Custom String Class

The StrType Class

The Constructors and Destructors

I/O on Strings

The Assignment Functions

Concatenation

Substring Subtraction

The Relational Operators

Miscellaneous String Functions

The Entire StrType Class

Using the StrType Class

Creating and Integrating New Types in General

A Challenge

40 Parsing Expressions

Expressions

Parsing Expressions: The Problem

Parsing an Expression

The Parser Class

Dissecting an Expression

A Simple Expression Parser

Understanding the Parser

Adding Variables to the Parser

Syntax Checking in a Recursive-Descent Parser

Building a Generic Parser

Some Things to Try

A The .NET Managed Extensions to C++

The .NET Keyword Extensions

Preprocessor Extensions

The attribute Attribute

Compiling Managed C++

B C++ and the Robotics Age