C++ All-In-One Desk Reference For Dummies, 2nd Edition.pdf

(83376 KB) Pobierz
ALL-IN
zyxwvutsrponmlkjihgfedcbaWVTSRONMLJIECBA
-ONE
zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA
c++
FOR
yxwvutsrqponmlkjihgfedcbaYXWVUTPONLIGFDCBA
zyxwvutsrqponmlkjihgfedcbaYXWVUTSRQPONMLKJIH
DUMMIES'*
2N D EDITION
zyxwvutsrqponmlkjihgfedcbaZYXWV
ywvutsrponlkhgfedcbaVTSPOMKJIG
by John Paul Mueller and Jeff Cogsw e ll
WILEY
Wiley Publishing, Inc.
www.allitebooks.com
Disclaimer: This eBo o k does not include ancillary media that w as packaged w ith the
printed version o f the bo o k.
zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA
C++ All-in-One For D ummies? 2nd Edition
Published b y
W il ey Pub l ishing, Inc.
I l l River Street
H oboken, N J 07030- 5774
w w w .w iley .co m
Copyright © 2 0 0 9 by W iley Publishing, Inc., Indianapolis, Indiana
Published b y W iley Publishing, Inc., Indianapolis, Indiana
Published sim ul taneousl y in C anada
N o part of this pub lication m ay b e rep ro d uced , sto red in a retrieval s y s tem or transm itted in any f orm
or by any m eans, el ectronic, m echanical , photocopying, record ing, scanning or otherw ise, excep t as
perm itted under S ections 107 or 108 of the 1976 United States Copyright A ct, w ithout either the prior
w ritten perm ission of th e Publisher, or authoriz ation thro ug h p aym ent of the ap p ro p ri ate p er- co p y f ee
to the Copyright C l earance Center, 222 Ro sew o o d D rive, D anvers, M A 01923, ( 9 7 8 ) 750- 8400, f ax ( 9 7 8 )
646- 8600. Req uests to the Pub lisher for perm ission shoul d b e ad d res s ed to the Perm issio ns D epartm ent,
Jo hn W iley & Sons, Inc., 111 River Street, H oboken, N J 07030, ( 2 0 1 ) 748- 6011, f ax ( 2 0 1 ) 748- 6008, or online
at h t t p : / /www. w i l e y . c o m / g o / p e r m i s s i o n s .
T rad e m ark s : W iley, the W iley Publishing logo, For D ummies, the D ummies M an logo, A Ref erence for the
Rest of Us!, T h e D ummies W ay, D ummies D aily, T h e Fun and Eas y W ay, D um m ies.com , M aking Everything
Easier, and rel ated trad e d res s are trad em ark s or registered trad em ark s of Jo hn W iley & Sons, Inc. an d /
or its affiliates in the United States and o ther countries, and m ay not b e used w ithout w ritten permission.
All o ther trad em ark s are the p ro p erty of their resp ecti v e ow ners. W iley Publishing, Inc., is not as s o ci ated
with any p ro d uct or v en d o r m entioned in this b ook.
LIM IT O F LIA BILITY/ D ISCLA IM ER O F W A RRA N T Y : T H E PU BLISH ER A N D T H E A U TH O R M A K E N O
REPRESEN TA TIO N S O R W A RRA N TIES W IT H RESPEC T T O TH E A CCU RA CY O R CO M PLETEN ESS O F
T H E CO N TEN TS O F TH IS W O RK A ND SPECIFICA LLY D ISCLA IM A LL W A RRA N TIES, INCLUDING W ITH-
O UT LIM ITA TIO N W A RRA N TIES O F FITN ESS FO R A PA RTICULA R PURPO SE. NO W A RRA N TY M A Y BE
CREA TED O R EXTEN D ED BY SA LES O R PRO M O TIO N A L M A TERIA LS. T H E A D V ICE A N D STRA TEG IES
CO N TA IN ED HEREIN M A Y N O T BE SUITA BLE FO R EV ERY SITUA TIO N . TH IS W O RK IS SO LD W ITH T H E
UN D ERSTA N D IN G TH A T T H E PUBLISH ER IS N O T EN G A G ED IN REN D ERIN G LEG A L A CCO UN TIN G . O R
O T H ER PRO FESSIO N A L SERV ICES. IF PRO FESSIO N A L A SSISTA N CE IS REQ UIRED , T H E SERV ICES O F
A CO M PETEN T PRO FESSIO N A L PERSO N SHO ULD BE SO UG H T. N EITH ER TH E PUBLISH ER N O R T H E
A UTH O R SHA LL BE LIA BLE FO R D A M A G ES A RISIN G H EREFRO M . T H E FA CT TH A T A N O RG A N IZ A TIO N
O R W EBSITE IS REFERRED TO IN TH IS W O RK A S A CITA TIO N A N D / O R A PO TEN TIA L SO URCE O F FUR-
TH ER IN FO RM A TIO N D O ES N O T M EA N THA T T H E A UTH O R O R TH E PUBLISHER EN D O RSES TH E INFOR-
M A TIO N T H E O RG A N IZ A TIO N O R W EBSITE M A Y PRO V ID E O R RECO M M EN D A TIO N S IT M A Y M A KE.
FURTHER, REA D ERS SHO ULD BE AW A RE TH A T IN TERN ET W EBSITES LISTED IN THIS W O RK M A Y HA V E
CH A N G ED O R D ISA PPEA RED BETW EEN W H EN TH IS W O RK W A S W RITTEN A N D W H EN IT IS REA D .
For general inf ormation on o u r other p ro d u cts and serv ices, p l ease co n tact our C usto m er Care
D epartm ent within the U.S. at 877- 762- 2974, outside the U.S. at 317- 572- 3993, or f ax 317- 572- 4002.
For technical sup p o rt, pl ease visit w w w . w i l e y . c o m / t e c h s u p p o r t .
W iley al so pub lishes its b ooks in a variety of el ectro nic f orm ats. S o m e co ntent that ap p ears in print m ay
not b e available in el ectro nic b ooks.
Lib rary of C o ng ress Control N um b er: 2 0 0 9 9 3 2 7 1 0
ISBN: 978- 0- 470- 31735- 8
M anuf actured in the United States of A m erica
10
9 8 7 6 5 4 3 2 1
WILEY
www.allitebooks.com
Contents at a Glance
Introduction
Chapter 1: Creating a First C++ Program
Chapter 2: Storing Data in C++
Chapter 3: Directing Your C++ Program Flow
Chapter 4: Dividing Your W ork with Functions
Chapter 5: Dividing Between Source-Code Files
Chapter 6: Referring to Your Data through Pointers
Chapter 7: W orking with Classes
Chapter 8: Using A dvanced C++ Features
zyxwvutsrqponmlkjihgfedcbaXWV
1
Book 1: Introducing
yvutsrponmljihgecaWTRQOMJHGDCBA
C++
7
9
29
59
83
109
123
151
187
Book 11: Understanding Objects and Classes
Chapter 1: Planning and Building O bjects
Chapter 2: Describing Your Program with UML
Chapter 3: Structuring Your Classes with UML
Chapter 4: Demonstrating Behavior with UML
Chapter 5: Modeling Your Programs with UML
Chapter 6: Building with Design Patterns
223
225
255
275
287
305
317
Book 111: Fixing Problems
Chapter 1: Dealing with Bugs
Chapter 2: Debugging a Program
Chapter 3: Stopping and Inspecting Your Code
Chapter 4: Traveling About the Stack
347
349
361
373
385
Book IV: Advanced Programming
Chapter 1: W orking with A rrays, Pointers, and References
Chapter 2: Creating Data Structures
Chapter 3: Constructors, D estructors, and Exceptions
Chapter 4: A dvanced Class Usage
Chapter 5: Creating Classes with Templates
Chapter 6: Programming with the Standard Library
395
397
427
449
477
503
535
www.allitebooks.com
Book V: Reading and W riting Files
Chapter 1: Filing Information with the Streams Library
Chapter 2: W riting with Output Streams
Chapter 3: Reading with Input Streams
Chapter 4: Building Directories and Contents
Chapter 5: Streaming Your Own Classes
567
569
583
597
609
619
Book VI: Advanced C++
Chapter 1: Exploring the Standard Library Further
Chapter 2: Building Original Templates
Chapter 3: Investigating Boost
Chapter 4: Boosting up a Step
631
633
651
671
697
Book Vll: Building Applications W ith M icrosoft M FC... 713
Chapter 1: W orking with the Visual C++ 2008 IDE and Projects
Chapter 2: Creating an MFC Dialog Box Project
Chapter 3: Creating an MFC SDI Project
Chapter 4: Using the Visual C++ 2008 Debugger
Chapter 5: Analyzing Your Visual C++ 2008 Code
715
731
747
769
779
Appendix A: Automating \lour
Programs W ith M akefiles
Appendix B: About the CD
Index
785
797
801
www.allitebooks.com
Table of Contents
Introduction
No Experience N ecessary
Great for Advanced Folks, Too!
For All Computers
Conventions
Organization
Icons Galore
W hat's Next?
zyxwvutsrqponmlkjihgfedcbaXWVUT
1
1
1
2
2
3
4
5
Book 1: Introducing
yvutsrponmljihgecaWTRQOMJHGDCBA
C++
Chapter 1: Creating a First C++ Program
Creating a Project
Understanding projects
Defining your first project
Building and executing your first application
Typing the Code
Starting with Main
Showing Information
Doing some math
Tabbing your output
Let Your Program Run Away
7
9
9
10
10
15
16
17
18
22
26
27
Chapter 2: Storing Data in C++
Putting Your Data Places: Variables
Creating an integer variable
Declaring multiple variables
Changing values
Setting one variable equal to another
Initializing a variable
Creating a great name for yourself
Manipulating Integer Variables
Adding integer variables
Subtracting integer variables
Multiplying integer variables
Dividing integer variables
Characters
Null character
Nonprintable and other cool characters
29
30
30
33
33
34
35
36
37
38
41
43
43
45
46
46
www.allitebooks.com
Zgłoś jeśli naruszono regulamin