Professional Documents
Culture Documents
tw
(02)2705-5066
www.wunan.com.tw
(02)2705-5066
C++
C++ C++
C++
C++
1.
(1)
(2) C++
(3)
C++
(4)
(5)
2.
(1) C++
C++
(2)
www.wunan.com.tw
(02)2705-5066
(3) 1 2
1 3
(4) C++
3 2 C++
C++
2 C++
(5)
C++ 4
3.
(1) C++
C++
C++
(2) C++
4.
C++
C++
C++
C++
C++
C++
www.wunan.com.tw
(02)2705-5066
1 2
3
4
C++
www.wunan.com.tw
(02)2705-5066
1
2
3
C++
1.1C++
1.2C++
1.3
C++ C++
2.1 C++
7
8
2.2
13
2.3C++
15
2.4C++
54
Step by Step
C++
57
3.1
58
3.2
66
3.3C++
67
3.4C++
82
www.wunan.com.tw
(02)2705-5066
4
5
6
C++
85
4.1
86
4.2
89
4.3C++
91
4.4C++
102
C++
105
5.1
106
5.2
109
5.3C++
111
5.4C++
130
133
6.1
134
6.2
136
6.3
137
6.4
154
www.wunan.com.tw
(02)2705-5066
7
8
9
10
157
7.1
158
7.2
162
7.3
164
7.4
176
177
8.1
178
8.2
183
8.3
185
8.4
223
225
9.1
226
9.2
230
9.3
231
9.4
261
263
10.1
264
www.wunan.com.tw
(02)2705-5066
11
12
13
10.2
265
10.3
267
10.4
272
275
11.1
276
11.2
279
11.3
280
11.4
283
285
12.1
286
12.2
288
12.3
289
12.4
303
305
13.1
306
13.2
314
13.3
316
www.wunan.com.tw
(02)2705-5066
14
15
16
13.4
325
327
14.1
328
14.2
332
14.3
333
14.4
340
343
15.1
344
15.2
347
15.3
349
15.4
355
357
16.1
358
16.2
361
16.3
362
16.4
369
www.wunan.com.tw
(02)2705-5066
17
18
19
20
371
17.1
372
17.2
374
17.3
376
17.4
378
379
18.1
380
18.2
387
18.3
389
18.4
406
409
19.1
410
19.2
413
19.3
415
19.4
432
435
20.1
436
20.2
442
www.wunan.com.tw
(02)2705-5066
20.3
452
20.4
485
487
498
www.wunan.com.tw
(02)2705-5066
1
C++
1.1C++
1.2C++
1.3
www.wunan.com.tw
(02)2705-5066
Chapter 1C++
1.1C++
C++
C++
C++
C++
C++
1.1.1 C++
C++ C++
C++
C++
C++ C++
C++ C++
C++
t = + t
C++
t=5+6;
cout<<"t="<<t;
t=11;
t = + cout
t =
www.wunan.com.tw
(02)2705-5066
1.1C++
t = 11 C++
C++
C++
C++
1.1.2 C++
C++ C++
1. C++
C++
. C++
. C++
. C++
1.1.3 C++
C++
C++
C++
C++
C++
www.wunan.com.tw
(02)2705-5066
Chapter 1C++
1.2C++
C++ C++
C++ C++
1.2.1 C++
C++
C++
1.2.2 C++
C++
C++
C++
C++
C++
C++ C++
C++
www.wunan.com.tw
(02)2705-5066
1.2C++
C++
C++
C++
C++
C++
C++
,000 C++
C++
C++ C++
C++
C++
www.wunan.com.tw
(02)2705-5066
Chapter 1C++
C++
C++ C++
C++
C++
C++ C++
C++
C++
C++
1.3
1. C++
. C++
www.wunan.com.tw
(02)2705-5066
2
C++C++
2.1 C++
2.2
2.3C++
2.4C++
www.wunan.com.tw
(02)2705-5066
Chapter 2C++C++
C++ C++ C++
C++ Visual C++
C++ C++
1.
2. 2-1
2.1C++
2-1 Happy new day C++
1.
C++
C++
2-1
2-1
www.wunan.com.tw
(02)2705-5066
2.1C++
2-1
2.
C++ C++
C++
C++ C++
cout
cout
(1)
void main()
// main()
//
www.wunan.com.tw
(02)2705-5066
Chapter 2C++C++
//
//
(2) [ ]
(3) ///**/
/*ch1_1.cpp*/
// ch1_1.cpp
#include<iostream.h>
// cout
void main()
// main()
//
//
(2) main()
main()
C++ main()
void main()
(3) {}{
}{}
(4) cout
10 www.wunan.com.tw
(02)2705-5066
2.1C++
\n
cout<<endl;cout<<
cout<<
3 3-1
3. C++
2.3.5 2.3.6
(1)
(2) C++
ch1_1.obj - 102 error(s), 0 warning(s) 102
www.wunan.com.tw 11
(02)2705-5066
Chapter 2C++C++
102
C++
C++
C++
C++
C++
D:\vc\Cbook\ ch1_1.cpp(11) : error C2143: syntax error : missing ; before
}
2-1
2-1
2-2
12 www.wunan.com.tw
(02)2705-5066
2.2
2-2
2.2
C++
1 C++
3 C++
www.wunan.com.tw 13
(02)2705-5066
Chapter 2C++C++
C++
C++
2.2.1
1. C++ C++
2.
3. C++
4.
5. C++
6. y = x-3 y x 3 x = 6
x = 14x = -1 y
7.
.
. C++
10.
2.2.2
1. C++
2. C++
3. 10 3
2.2.3
2-2
14 www.wunan.com.tw
(02)2705-5066
2.3C++
4
4
2-2
C++
90
8089
6079
<60
2-2C++%
2.3C++
C++
C++
C++ C++
C++ C++
C++
2.3.1 C++
C++
www.wunan.com.tw 15
(02)2705-5066
Chapter 2C++C++
C++
Y
C++
2-3 C++
16 www.wunan.com.tw
(02)2705-5066
2.3C++
C++ 2-3
1.
2-3 5
C++
2.
2-3 6 7 C++
C++
C++ C++
www.wunan.com.tw 17
(02)2705-5066
Chapter 2C++C++
(1)
(2)
(3)
18 www.wunan.com.tw
(02)2705-5066
2.3C++
Visio
3. C++
2-3
C++
obj C++
Visual C++6.0
Debug
exe
Visual C++6.0
Visual C++6.0
2.3.2 C++
www.wunan.com.tw 19
(02)2705-5066
Chapter 2C++C++
C++
C++
2-4
2-4
2-1
2.3.3 C++C++
C++
C++
C++ C++ C++
C++ 2-4
2-1
C++
2-1
C++ C++
/**///
/**/// 2-1
20 www.wunan.com.tw
(02)2705-5066
2.3C++
C++
C++ .
C++ 26
0
2.3.4 cout
C++ C++
C++ C++
cout
cout
1. cout
cout
.3.5
2. cout
cout C++
cout
www.wunan.com.tw 21
(02)2705-5066
Chapter 2C++C++
cout<< 1
endl
3. cout
cout cout
2-2 C++
cout<<endl; // '\n' endl
//
cout<<'\n';
cout<<" I am a student.\n";//
cout<<3+5<<endl; // 8
22 www.wunan.com.tw
(02)2705-5066
2.3C++
cout
cout
125MB 600MB
Visual C++6.0 Setup.exe
www.wunan.com.tw 23
(02)2705-5066
Chapter 2C++C++
space
C++ Output
WorkspaceFileView
ClassView
(02)2705-5066
2.3C++
3.
Visual C++ 6.0
(1)Standard
2-6
2-6Standard
2-7Build Minibar
CompileBuildStop Build
Execute ProgramGo
F5Insert/Remove Breakpoint
(3)Build Build Minibar
www.wunan.com.tw 25
(02)2705-5066
Chapter 2C++C++
2-
2-8Build
(5)Resource 2-10
New Dialog New Menu
New CursorNew IconNew
BitmapNew ToolbarNew Accelerator
New String TableNew Version
Resource Symbols
2-9Debug 2-10Resource
(6)WizardBar 2-11
26 www.wunan.com.tw
(02)2705-5066
2.3C++
2-11WizardBar
(1)File 2-12
New Open Close Open
WorkspaceSave WorkspaceClose Workspace
SaveSave AsSave All
Page SetupPrintRecent FilesRecent
WorkspacesExit
(2)Edit 2-13
2-12File 2-13Edit
UndoRedoCut
www.wunan.com.tw 27
(02)2705-5066
Chapter 2C++C++
CopyPasteDeleteSelect AllFind
Find in FilesReplace Go To
(3)View 2-14
ClassWizardResource Symbols
Resource IncludesFull ScreenWorkspaceOutputDebug Windows
RefreshProperties
(4)Insert 2-15
New ClassNew FormResourceResource CopyFile As Text
New ATL Object ATL
2-14View 2-15Insert
(5)Project 2-16
Set Active ProjectAdd To Project
DependenciesSettingsExport Makele Makele Insert Proiect into Workspace
(6)Build 2-17
Start Debug Build Debug
CompileBuildRe28 www.wunan.com.tw
(02)2705-5066
2.3C++
build AllBatch BuildCleanStart Debug
Debugger Remote ConnectionExecuteSet
Active CongurationCongurationsProle
2-16Project 2-17Build
(7)Debug
2-1
GoExceptionsThreads
Modules
()Tools 2-1
2-18Debug 2-19Tools
www.wunan.com.tw 29
(02)2705-5066
Chapter 2C++C++
Register ControlError Lookup
ActiveX Control Test ContainerOLE/COM Object ViewerOLE
COM Spy++MFC TracerMFC Customize
Tools OptionsMacroRecord Quick
MacroPlay Quick Macro
()Window 2-20
New WindowSplitDocking
View Docking View CloseClose All
NextPreviousCascade
Tile HorizontallyTile VerticallyWindows
2-20Window 2-21Help
5.
30 www.wunan.com.tw
(02)2705-5066
2.3C++
F
F5
F11
F10
Shift+F5
www.wunan.com.tw 31
(02)2705-5066
Chapter 2C++C++
Visual C++ 6.0
1. C++
(1) C++
C++
FileNew
NewProjects
Win32 Console Application
Location
Project name a1
OK 2-24
32 www.wunan.com.tw
(02)2705-5066
2.3C++
1
2
2-24 C++
2-25 Finish
2-25 C++
www.wunan.com.tw 33
(02)2705-5066
Chapter 2C++C++
2-26 OK
C++
2-26 C++
(2) C++
C++
FileNew
NewFiles
C++ Source FileC/C++ Header File
File C++
C++ stu
OK 2-27
FileView 2-2
2-2 a1
34 www.wunan.com.tw
(02)2705-5066
2.3C++
1
3
4
2-27 C++
8
6
2-28 C++
www.wunan.com.tw 35
(02)2705-5066
Chapter 2C++C++
2-2 Source Files+
C++ stu.cppHeader
Files+
(3) C++
2-2 C++
Project
2-29 C++
Add To ProjectNew
Add To Project Files Insert
Files into Project
C++
2. C++
36 www.wunan.com.tw
(02)2705-5066
2.3C++
2-30
2-30 C++
FileSave
FileSave as
2-31
. st2 C++
st2.cpp .txt
www.wunan.com.tw 37
(02)2705-5066
Chapter 2C++C++
2-31 C++
3
File Save
FileSave all
3. C++Visual C++ 6.0
38 www.wunan.com.tw
(02)2705-5066
2.3C++
4. C++
2-33
2 FileOpen
FileOpen Workspace
Visual C++ 6.0
2-34
www.wunan.com.tw 39
(02)2705-5066
Chapter 2C++C++
1
4
2-33 C++
2-34 C++
40 www.wunan.com.tw
(02)2705-5066
2.3C++
5. C++
2-33
Workspacesdsw.mdp
dsw dsw
1 (3) C++
6. C++
C++
C++ C++
cpp
7. C++
C++
Build Minibar
C++
Text1.dsw
8. C++
FileView
Delete Edit Delete
Delete
9.
www.wunan.com.tw 41
(02)2705-5066
Chapter 2C++C++
10.
Build Minibar
2-35
Ctrl+F7BuildCompile
2-35 C++
2-36
2-35
p7132.obj
42 www.wunan.com.tw
(02)2705-5066
2.3C++
obj
C++ C++
2-36 C++
11.
Build Minibar
2-36
F7BuildBuild
2-37
p7132.exe
exe
www.wunan.com.tw 43
(02)2705-5066
Chapter 2C++C++
2-37
Build
Minbar Visual C++ 6.0
12.
Build Minibar
2-3
Ctrl+F5BuildExecute
2-3
Debug
44 www.wunan.com.tw
(02)2705-5066
2.3C++
2-38
2-3
Press any key to continue
13. Debug
Debug
www.wunan.com.tw 45
(02)2705-5066
Chapter 2C++C++
BuildStart DebugStep IntoF11
Debug
2-3
F11
F10
F5
2-41
Build Minibar
F
Build Minibar
F
F5 2-42
Build Minibar
2-43
Watch
Enter 2-44
Debug
2-39
46 www.wunan.com.tw
(02)2705-5066
2.3C++
2-40
2-41
www.wunan.com.tw 47
(02)2705-5066
Chapter 2C++C++
2-42F5
2-43
48 www.wunan.com.tw
(02)2705-5066
2.3C++
2-44
14. C++Help
MSDN Visual C++ 6.0 Help
Visual C++ Programmers GuideVisual C++ C/C++ Language
and C++ LibrariesC/C++ C++ Microsoft Foundation Class
Library and Templates
C++
MSDN 2-45
3
4 ContentsIndexSearch
Favorites 4
MSDN
www.wunan.com.tw 49
(02)2705-5066
Chapter 2C++C++
2-45MSDN
(1) Help
Visual C++ 6.0HelpContents Index
Search MSDN 2-45
Index main
Display main
2-46
Visual C++ 6.0
coutF1
cout 2-47
50 www.wunan.com.tw
(02)2705-5066
2.3C++
2-46 main
2-47 cout
www.wunan.com.tw 51
(02)2705-5066
Chapter 2C++C++
(2) 4
+
Display
Display
structList
Topics
Display 2-4
struct
A.
struct
FavoritesCurrent topic
stAddTopics
st struct
B.
Favorites stDisplay struct 2-4
52 www.wunan.com.tw
(02)2705-5066
2.3C++
2-48 struct
2-49st struct
www.wunan.com.tw 53
(02)2705-5066
Chapter 2C++C++
C.
Favorites st Removest
(3)
2.4C++
C++
1. C++
C++
(1)
(2) C++
(3)
(4)
2. C++
(1)
(2)
(3)
(4)
54 www.wunan.com.tw
(02)2705-5066
2.4C++
3. C++ C++
(1)
(2)
(3) C++ { }
;
(4)
(5)
(6)
4. cout
(1) cout
(2) cout <<
(3)
5. C++
(1)
(2) C++
(3) C++
www.wunan.com.tw 55
(02)2705-5066
A C/C++
BASCII
www.wunan.com.tw
(02)2705-5066
AC/C++
1. math.h
int abs(int n) n
-
488
www.wunan.com.tw
(02)2705-5066
AC/C++
long double fmodl(long double x, long double y);
double hypot(double x, double y);
long int labs(long int n); n
double log(double x); ln(x)
long double logl(long double x);
double log10(double x); log10(x)
long double log10l(long double x);
double pow(double x,double y); xy
long double powl(long double x,long double y);
double sin(double x); sin (x) x
long double sinl(long double x);
double sinh(double x); x
long double sinhl(long double x);
double sqrt(double x); x
long double sqrtl(long double x);
double tan(double x); tan (x) x
long double tanl(long double x);
double tanh(double x); x
long double tanhl(long double x);
2. ctype.h
int isalnum(int ch); ch ch A Za z
0 9 0 0
int isalpha(int ch); ch ch A Z a z
0 0
int iscntrl(int ch); ch ASCII 0~0X1F DEL
ASCII 0X7F 0 0
int isdigit(int ch); ch ch
0 9 0 0
www.wunan.com.tw 489
(02)2705-5066
int isgraph(int ch); ch ASCII
0X21 0X7E 0 0
int islower(int ch); ch ch
0 0
int isprint(int ch); ch ASCII 0X20 0X7E
0 0
int ispunct(int ch); ch
0 0
int isspace(int ch); ch ASCII 0X09 0X0D
0
0
int isupper(int ch); ch ch
0 0
int isxdigit(int ch); ch ch
0 9A F a f 0 0
int tolower(int ch); ch
int toupper(int ch); ch
3. string.h
size_t unsigned int
void *memchr(const void*s,int ch,size_t n); n ch
NULL
int memcmp(const void*s1, const void*s2,size_t n); s1 s2
n s1 s2 <0 s1 s2
=0 s1 s2 >0
int memicmp(const void*s1, const void*s2,size_t n); s1 s2
n memcmp() memicmp()
void *memcpy(void*dest, const void*src,size_t n); src n
dest dest src dest memcpy
490
www.wunan.com.tw
(02)2705-5066
AC/C++
maxlen strcmp()
char *strcpy(char*dest, const char*src); src dest NULL
dest
char *strncpy(char*dest, const char*src, size_t maxlen); src
maxlen src maxlen dest dest maxlen
NULL dest src
maxlen dest NULL
char*strdup(const char*s); s malloc()
strlen(s)+1 strdup
www.wunan.com.tw 491
(02)2705-5066
NULL
size_t strlen(const char*s); s s
NULL
char*strlwr(char*s);
char*strupr(char*s);
char*strset(char*s,int ch); ch NULL
time.h tm
struct tm
{
int tm_sec;//
int tm_min;//
int tm_hour;// 0 23
int tm_mday;// 1 31
int tm_mon;// 0 11
int tm_year;// 1900
492
www.wunan.com.tw
(02)2705-5066
AC/C++
int tm_wdqy;// 0 6 0
int tm_yday;// 1 1
};
www.wunan.com.tw 493
(02)2705-5066
(2)
iomanip.h I/O
#include<iomanip.h>
cout<< ;
setprecision(n)
(setiosags(ios::xed)),setprecision(n)
(setiosags(ios::scientic)),setprecision(n)
setprecision(6)
setw(n); n n
n
16
setiosags(ios::uppercase); 16
setll(c); c
c
setiosags(ios::left);
setiosags(ios::right);
setiosags(ios::showpoint);
setiosags(ios::showpos);
494
www.wunan.com.tw
(02)2705-5066
AC/C++
resetiosags( );
, ios::showpos, ios::dec
6. stdlib.h
double atof(const char*str); str double
int atoi(const char*str); str int
char*itoa(int num,char*str,int radix); num
str radix
long atol(const char*str); str long int
char*ltoa(long num, char*str,int radix); num
str radix
void exit(int status);
void abort(void);
int rand (void);
void srand (unsigned x); x
7. conio.h
int getch(void);
int getche(void);
int putch(int ch); ch
int kbhit(void); 0
0
C/C++ Visual C++ 6.0
Help C/C++
DOS
system("DOS "); // 2
#include<windows.h>//
www.wunan.com.tw 495
(02)2705-5066
#include<windows.h>
system("cls");//
system("type d:\\6df\\test2.txt");// test2
BASCII
ASCII
16
ASCII
16
ASCII
16
NUL
00
20
DC4
14
40
28
SOH
01
21
NAK
15
41
29
STX
02
22
SYN
16
42
2A
ETX
03
23
ETB
17
43
2B
EOT
04
24
CAN
18
44
2C
ENQ
05
25
EM
19
45
2D
ACK
06
26
SUB
1A
46
2E
BEL
07
27
ESC
1B
47
2F
BS
08
28
FS
1C
48
30
HT
09
29
GS
1D
49
31
10
LF
0A
30
RS
1E
50
32
11
VT
0B
31
US
1F
51
33
12
FF
0C
32
Space
20
52
34
13
CR
0D
33
21
53
35
14
SO
0E
34
22
54
36
15
SI
0F
35
23
55
37
16
DLE
10
36
24
56
38
17
DC1
11
37
25
57
39
18
DC2
12
38
&
26
58
3A
19
DC3
13
39
27
59
3B
496
www.wunan.com.tw
(02)2705-5066
BASCII
ASCII
16
ASCII
16
ASCII
16
60
<
3C
83
53
106
6A
61
3D
84
54
107
6B
62
>
3E
85
55
108
6C
63
3F
86
56
109
6D
64
40
87
57
110
6E
65
41
88
58
111
6F
66
42
89
59
112
70
67
43
90
5A
113
71
68
44
91
5B
114
72
69
45
92
5C
115
73
70
46
93
5D
116
74
71
47
94
5E
117
75
72
48
95
5F
118
76
73
49
96
60
119
77
74
4A
97
61
120
78
75
4B
98
62
121
79
76
4C
99
63
122
7A
77
4D
100
64
123
7B
78
4E
101
65
124
7C
79
4F
102
66
125
7D
80
50
103
67
126
7E
81
51
104
68
127
DEL
7F
82
52
105
69
031
www.wunan.com.tw 497
(02)2705-5066
1. Bjarne StroustrupThe C++ Programming Language
2001
2. C++ 2004
3. C++ 1999
4. Visual C++ 6.0
2004
5. C++
2003
6. C++ 1999
7. 2009
31102-105
8. C++ 2008529-30
9.
200821636-3740
www.wunan.com.tw
(02)2705-5066
C++.
., 2013.10
ISBN 978-957-11-7299-6 ()
1.C++
312.32C
102016930
5DG5
C++
106 3 3 9 4
(02)2705-5066(02)2706-6100
http://www.wunan.com.tw
wunanwunan.com.tw
0 1 0 6 8 9 5 3
/6
(04)2223-0891(04)2223-3549
/290
(07)2358-702 (07)2350-236
2 0 1 3 1 0
5 8 0
www.wunan.com.tw
(02)2705-5066