!=. See Not equal (inequality), 67, 1088, 1101
"...". See String literal, 62
#. See Preprocessor directives, 1129
$. See End of line, 873, 1178
%. See Output format specifier, 1187
Remainder (modulo), 68
%=. See Remainder and assign, 1090
&. See Address of, 588, 1087
Bitwise logical operations (and), 956, 1089, 1094
Reference to (in declarations), 276–279, 1099
&&. See Logical and, 1089, 1094
&=. See Bitwise logical operations (and and assign), 1090
.'. .'. See Character literals, 161, 1079–1080
(). See Expression (grouping), 95, 867, 873, 876
Function of (in declarations), 113–115, 1099
Regular expression (grouping), 1178
*. See Contents of (dereference), 594
Multiply, 1088
Pointer to (in declarations), 587, 1099
Repetition (in regex), 868, 873–874, 1178
*/ end of block comment, 238
*=. See Multiply and assign (scale), 67
Concatenation (of strings), 68–69, 851, 1176
Repetition in regex, 873–875, 1178
+=. See Add and assign, 1089
Move forward, 1101
string (add at end), 851, 1176
, (comma). See Comma operator, 1090
List separator, 1103, 1122–1123
–. See Minus (substraction), 66, 1088
Regular expression (range), 877
––. See Decrement, 66, 1087, 1141
–> (arrow). See Member access, 608, 1087, 1109, 1141
–= See Move backward, 1101, 1142
. (dot). See Member access, 306, 607–608, 1086–1087
... (ellipsis). See Arguments (unchecked), 1105–1106
Catch all exceptions, 152
//. See Line comment, 45
/*. . .*/. See Block comment, 238
/=. See Divide and assign, 67, 1090
: (colon). See Base and member initializers, 315, 477, 555
Conditional expression, 268
Label, 106–108, 306, 511, 1096
::. See Scope (resolution), 295, 314, 1083, 1086
; (semicolon). See Statement (terminator), 50, 100
<<. See Bitwise logical operations (left shift), 956, 1088
<=. See Less than or equal, 67, 1088
<<=. See Bitwise logical operations (shift left and assign), 1090
<. . .>. See Template (arguments and parameters), 153, 678–679
=. See Assignment, 66, 1090
>. See Greater than, 67, 1088
Input prompt, 223
Template (argument-list terminator), 679
>=. See Greater than or equal, 67, 1088
>>. See Bitwise logical operations (right shift), 956, 1088
>>=. See Bitwise logical operations (shift right and assign), 1090
?. See Conditional expression, 268, 1089
Regular expression, 867–868, 873, 874–875, 1178
[]. See Array of (in declaration), 649, 1099
Regular expression (character class), 872, 1178
(backslash). See Character literal, 1079–1080
Escape character, 1178
Regular expression (escape character), 866–867, 873, 877
^. See Bitwise logical operations (exclusive or), 956, 1089, 1094
Regular expression (not), 873, 1178
^=. See Bitwise logical operations (xor and assign), 1090
_. See Underscore, 75, 76, 1081
{}. See Block delimiter, 47, 111
Initialization, 83
List, 83
Regular expression (range), 867, 873–875, 1178
|. See Bitwise logical operations (bitwise or), 956, 1089, 1094
Regular expression (or), 867–868, 873, 876, 1178
|=. See Bitwise logical operations (or and assign), 1090
||. See Logical or, 1089, 1094
~. See Bitwise logical operations (complement), 956, 1087
0 (zero). See Null pointer, 598
printf() format specifier, 1188–1189
a, append file mode, 1186
a alert, character literal, 1079
abs(), absolute value, 917, 1181
class hierarchies, 512
Abstract-first approach to programming, 10
base classes, 511
encapsulation, 505
private: label, 306
protected: label, 511
public by default, 307–308. See also struct
public: label, 306
accumulate(), 759, 770–772, 1183
accumulator, 770
Action, 47
Activation record, 287. See also Stacks
Adaptors
bind(), 1164
container, 1144
function objects, 1164
mem_fn(), 1164
not1(), 1164
not2(), 1164
priority_queue, 1144
queue, 1144
stack, 1144
add(), 449–450, 491–492, 615–617
Add and assign +=, 66, 73, 1090
Additive operators, 1088
unchecked conversions, 943–944
Address of (unary) &, 588, 1087
adjacent_difference(), 770, 1184
adjacent_find(), 1153
Affordability, software, 34
Age distribution example, 538–539
Alert markers, 3
Algol family of languages, 826–829
Algorithms, 1217
and containers, 722
passing arguments to. See Function objects
Algorithms, numerical, 770, 1183–1184
accumulate(), 759, 770–774, 1183
adjacent_difference(), 770, 1184
inner_product(), 759, 770, 774–776, 1184
<algorithm>, 759
binary_search(), 796
comparing elements, 759
copy_if(), 789
copying elements, 758
count(), 758
count_if(), 758
equal(), 759
heap, 1160
lower_bound(), 796
max(), 1161
merge(), 758
merging sorted sequences, 758
min(), 1161
nonmodifying sequence, 1153–1154
numerical. See Algorithms, numerical
searching, 1157–1159. See also find_if(); find()
sorting, 758, 794–796, 1157–1159
summing elements, 759
unique_copy(), 758, 789, 792–793
upper_bound(), 796
utility, 1157
Aliases, 1128, 1217. See also References
Allocating memory. See also Deallocating memory; Memory
allocator_type, 1147
bad_alloc exception, 1094
calloc(), 1193
embedded systems, 935–936, 940–942
realloc(), 1045
allocator_type, 1147
alnum, regex character class, 878, 1179
alpha, regex character class, 878, 1179
Alternation
patterns, 194
regular expressions, 876
Ambiguous function call, 1104
and, synonym for &, 1037, 1038
and_eq, synonym for &=, 1037, 1038
Append
string +=, 851
Application
collection of programs, 1218
operator (), 766
Arccosine, acos(), 917
Arcsine, asin(), 918
Arctangent, atan(), 918
arg(), of complex number, theta, 920, 1183
Argument errors
callee responsibility, 143–145
caller responsibility, 142–143
formal. See Parameters
passing. See Passing arguments
program input, 91
types, class interfaces, 324–326
unchecked, 1029–1030, 1105–1106
unexpected, 136
Arithmetic if ?:, 268. See also Conditional expression ?:
Arithmetic operations. See Numerics
<array>, 1133
Arrays, 648–650, 1218. See also Containers; vector
[] declaration, 649
[] dereferencing, 649
accessing elements, 649, 899–901
associative. See Associative containers
dereferencing, 649
element numbering, 649
initializing, 596–598, 654–656
multidimensional, 895–897, 1102
passing pointers to arrays, 944–951
range checking, 649
subscripting [], 649
array standard library class, 747–749, 1144
asm(), assembler insert, 1037
Assemblers, 820
Assertions
assert(), 1061
<cassert>, 1135
debugging, 163
definition, 1218
assign(), 1148
assignment and initialization, 69–73
composite assignment operators, 73–74
containers, 1148
string, 851
Assignment operators (composite), 66
&=, 1090
<<=, 1090
>>=, 1090
^=, 1090
|=, 1090
Associative arrays. See Associative containers
Associative containers, 776, 1144
header files, 776
map, 776
multiset, 776
set, 776
unordered_map, 776
unordered_multimap, 776
unordered_multiset, 776
unordered_set, 776
Assumptions, testing, 1009–1011
at(), range-checked subscripting, 693–694, 1149
atof(), string to double, 1192
atoi(), string to int, 1192
atol(), string to long, 1192
AT&T Bell Labs, 838
AT&T Labs, 838
attach() vs. add() example, 491–492
Automatic storage, 591–592, 1083. See also Stack storage
Axis example, 424–426, 443, 529–532, 543–546
b, binary file mode, 1186
Babbage, Charles, 832
back(), last element, 737, 1149
back_inserter(), 1162
Backus, John, 823
Backus-Naur (BNF) Form, 823, 828
bad_alloc exception, 1094
Base-2 number system (binary), 1078–1079
Base-8 number system (octal), 1077–1078
Base-10
logarithms, 918
number system (decimal), 1077–1078
Base-16 number system (hexadecimal), 1077–1078
Base and member initializers, 315, 477, 555
Base classes, 493–496, 504–507, 1218
abstract classes, 495, 512–513, 1118–1119
access control, 511
initialization of, 477, 555, 1113, 1117
virtual function calls, 501, 506–507
vptr, 506
vtbl, 506
Base-e exponentials, 918
basic_string, 852
Basic guarantee, 702
BCPL language, 838
begin()
iterator, 1148
vector, 721
Bell Telephone Laboratories (Bell Labs), 836, 838–842, 1022–1023
Bidirectional iterator, 1142
bidirectional iterators, 752
Big-O notation, complexity, 785
Binary number system, 1078–1079
Binary search, 758, 779, 795–796
bind() adaptor, 1164
bitand, synonym for &, 1037, 1038
Bitfields, 956–957, 967–969, 1120–1121
bitor, synonym for |, 1038
bool, 955
char, 955
enumerations, 956
integer types, 955
<bitset>, 1133
bitwise logical operations, 960
construction, 959
exceptions, 1138
I/O, 960
Bitwise logical operations, 956–959, 1094
or and assign, |=, 966
and and assign &=, 1090
complement ~, 956
exclusive or ^, 956, 1089, 1094
exclusive or and assign ^=, 1089
left shift <<, 956
left shift and assign <<=, 1089
right shift >>, 956
right shift and assign >>=, 1089
Blackboard, 36
blank, character class, regex, 878, 1179
Block, 111
debugging, 161
nesting within functions, 271
Block comment /*. . .*/, 238
Blue marginal alerts, 3
BNF (Backus-Naur) Form, 823, 828
Body, functions, 114
bits in memory, 78
bit space, 955
size, 78
boolalpha, manipulator, 1173
Boolean conversions, 1092
Borland, 831
Bounds error, 149
Branching, testing, 1006–1008. See also Conditional statements
break, case label termination, 106–108
Broadcast functions, 903
Buffer, 348
iostream, 406
overflow, 661, 792, 1006. See also gets(), scanf()
Bugs, 158, 1218. See also Debugging; Testing
regression tests, 993
default constructors, 328
exceptions, 1126
floating-point, 77, 891–895, 1100
integers, 77, 891–895, 961–965, 1100
references, 279–280, 1102–1103
attaching to menus, 571
detecting a click, 557
operations, C-style strings, 1048–1049
.c suffix, 1029
C# language, 831
C++ language, 839–842. See also Programming; Programs; Software
coding standards, list of, 983
portability, 11
C linkage convention, 1033
calling one from the other, 1032–1034
enum, 1042
family tree, 1023
layout rules, 1034
nesting structs, 1037
old-style casts, 1040
opaque types, 1060
performance, 1024
realloc(), 1045
void, 1030
“C first” approach to programming, 9
C language, 836–839. See also C standard library
C++ compatibility, 1022–1024. See also C++ and C
linkage convention, 1033
C-style strings, 1191
header files, 1135
input/output. See C-style I/O (stdio)
C-style casts, 1040–1041, 1087, 1095
%, conversion specification, 1187
conversion specifications, 1188–1189
file modes, 1186
files, opening and closing, 1186
getchar(), 1045, 1052–1053, 1191
output formats, user-defined types, 1189–1190
padding, 1188
stderr, 1189
stdin, 1189
stdout, 1189
truncation, 1189
C-style strings, 654–655, 1045–1047, 1191
executing as a command, system(), 1194
lexicographical comparison, 1046
pointer declaration, 1049–1050
strcat(), concatenate, 1047
strchr(), find character, 1048
strcmp(), compare, 1046
from string, c_str(), 350, 851
strlen(), length of, 1046
strncat(), 1047
strncmp(), 1047
strncpy(), 1047
three-way comparison, 1046
Calculator example, 174, 186–188
get_token(), 196
grammars and programming, 188–195
symbol table, 247
Token_stream, 206–214, 240–241
Call stack, 290
Callback implementation, 1208–1209
Calling functions. See Function calls
calloc(), 1193
Cambridge University, 839
Capital letters. See Case (of characters)
identifying, 397
map container, 782
tolower(), changing case, 398, 1176
toupper(), changing case, 398, 1176
<cassert>, 1135
Casts. See also Type conversion
casting away const, 609
const_cast, 1095
lexical_cast example, 855
narrow_cast example, 153
reinterpret_cast, 609
unrelated types, 609
CAT scans, 30
Catch all exceptions ., 152
Catching exceptions, 146–153, 239–241, 1126
<cerrno>, 1135
<cfloat>, 1135
Character classes
list of, 1179
in regular expressions, 873–874, 878
Character classification, 397–398, 1175–1176
Character literals, 161, 1079–1080
CHAR_BIT limit macro, 1181
CHAR_MAX limit macro, 1181
CHAR_MIN limit macro, 1181
bits, 955
built-in, 1099
cin, 61
C equivalent. See stdin
standard character input, 61, 347, 1169
vs. Ellipse, 474
Circular reference. See Reference (circular)
abstract, 495, 512–513, 1118–1119. See also Abstract classes
coding standards, 981
const member functions, 1110
constructors, 1112–1114, 1119–1120
creating objects. See Concrete classes
defining, 212, 305, 1108, 1218
derived, 504
encapsulation, 505
friend declaration, 1111
generated operations, 1119–1120
grouping related, 512
hierarchies, 512
history of, 834
member access. See Access control
naming. See Namespaces
nesting, 270
organizing. See Namespaces
parameterized, 682–683. See also Template
private, 306–308, 505, 511, 1108–1109
public, 306–308, 505, 511, 1108–1109
run-time polymorphism, 504–505
subclasses, 504. See also Derived classes
superclasses, 504. See also Base classes
this pointer, 1110
types as parameters. See Template
union, 1121
unqualified name, 1110
uses for, 305
const member functions, 330–332
constants, 330–332. See also const
symbolic constants, defining, 326
uninitialized variables, 327–330
:: (scope resolution), 1109
accessing, 306. See also Access control
allocated at same address, 1121
in-class definition, 1112
data, 305
definitions, 1112
out-of-class definition, 1112
Token_stream example, 212
specialization, 681
type generators, 681
classic_elimination() example, 910–911
Cleaning up code
<climits>, 1135
<clocale>, 1135
clock_t, 1193
clone() example, 504
Closed_polyline example, 456–458
vs. Polygon, 458
close() file, 352
Code
definition, 1218
libraries, uses for, 177
test coverage, 1008
C++, list of, 983
complexity, sources of, 975
Color example, 425–426, 450–452
transparency, 451
Columns, matrices, 900–901, 906
Command-line, 47
C++ and C, 1026
vs. code, 238
Common Lisp language, 825
Communication skills, programmers, 22
Compacting garbage collection, 938–939
Comparison, 67. See also <; ==
characters, 740
containers, 1151
key_compare, 1147
lexicographical, C-style strings, 1046
lexicographical_compare(), 1162
string, 851
three-way, 1046
Compatibility. See C++ and C
Compile-time errors. See Errors, compile-time
compile-time errors, 51
conditional compilation, 1058–1059
compl, synonym for ~, 1037, 1082
<<, output, 1183
!=, not equal (inequality), 919, 1183
<<, output, 920
abs(), absolute value, 920, 1183
conj(), conjugate, 920
Fortran language, 920
imag(), imaginary part, 920
norm(), square of abs(), 919
polar(), polar coordinate, 920
real(), real part, 920
rho, 920
square of abs(), 919
theta, 920
<complex>, 1134
complex operators, 919–920, 1183
standard math functions, 1181
Complexity, 1218
sources of, 975
Composite assignment operators, 73–74
Compound statements, 111
Computation, 91. See also Programs; Software
input/output, 91
Computer-assisted surgery, 30
Computers
CAT scans, 30
computer-assisted surgery, 30
information processing, 32
Mars Rover, 33
medicine, 30
space exploration, 33
timekeeping, 26
world total, 19
Concatenation of strings, 66
Concept-based approach to programming, 6
Concrete classes, 495–496, 1218
Concrete-first approach to programming, 6
Concurrency, 932
Conditional compilation, 1058–1059
Conditional expression ?:, 268, 1089
Conditional statements. See also Branching, testing
Conforming programs, 1075
Confusing variable names, 77
conj(), complex conjugate, 920, 1183
Conjugate, 920
Console, as user interface, 552
Console input/output, 552
Console window, displaying, 162
const, 95–97. See also Constant; Static storage, static const
initializing, 262
member functions, 330–332, 1110
passing arguments by, 276–278, 281–284
type, 1099
*const, immutable pointer, 1099
Constant. See also const, expressions, 1093
const_cast, casting away const, 609, 1095
const_iterator, 1147
constexpr, 96-97, 290-291, 1093, 1104
Constraints, vector range checking, 695
Constructors, 310–312, 1112–1114. See also Destructors; Initialization
containers, 1148
Date example, 311
initialization of bases and members, 315, 477, 555
need for default, 641
Token example, 184
Container adaptors, 1144
Containers, 148, 749–751, 1218. See also Arrays; list; map, associative array; vector
and algorithms, 722
assignments, 1148
of characters. See string
comparing, 1151
constructors, 1148
contiguous storage, 741
copying, 1151
destructors, 1148
element access, 1149
information sources about, 750
iterator categories, 752
iterators, 1148
list operations, 1150
member types, 1147
operations overview, 1146–1147
queue operations, 1149
sequence, 1144
size(), 1150
stack operations, 1149
swapping, 1151
Contents of * (dereference, indirection), 594
Contiguous storage, 741
Control characters, iscntrl(), 397
Control inversion, GUIs, 569–570
Control variables, 110
Controls. See Widget example
Conversion specifications, printf(), 1188–1189
Conversion. See also Type conversion
character case, 398
Coordinates. See also Point example
Copy assignments, 634–636, 640–646
Copy constructors, 633–634, 640–646
copy_backward(), 1154
copy_if(), 789
containers, 1151
C-style strings, 1046–1047, 1049
Correctness
definition, 1218
software, 34
cos(), cosine, 527–528, 917, 1181
cosh(), hyperbolic cosine, 1182
Cost, definition, 1219
cout, 45
C equivalent. See stdout
printing error messages, 151. See also cerr
Critical systems, coding standards, 982–983
<cstddef>, 1136
<cstdio>, 1135
c_str(), 1177
Ctrl D, 124
Ctrl Z, 124
Current object, 317. See also this pointer
Cursor, definition, 45
<cwchar>, 1136
<cwctype>, 1136
d, any decimal digit, regex, 878, 1179
d, decimal digit, regex, 873, 1179
D, not a decimal digit, regex, 873, 1179
d suffix, 1079
Data. See also Containers; Sequences; list; map, associative array; vector
abstraction, 816
collections. See Containers
in memory. See Free store (heap sotrage)
separating from algorithms, 722
storing. See Containers
structure. See Containers; class; struct
traversing. See Iteration; Iterators
uniform access and manipulation, 714–716. See also STL (Standard Template Library)
Data structure. See Data; struct
Data type. See Type
Date example, See Chapters 6–7
Deallocating memory, 598–600, 1094–1095. See also delete[]; delete
Debugging, 52, 158, 1219. See also Errors; Testing
assertions, 163
block termination, 161
bugs, 158
character literal termination, 161
compile-time errors, 161
consistent code layout, 160
declaring names, 161
displaying the console window, 162
expression termination, 161
function size, 160
input data, 166
keeping it simple, 160
matching parentheses, 161
naming conventions, 160
reporting errors, 159
stepping through code, 162
string literal termination, 161
testing, 1012
tracing code execution, 162–163
transient bugs, 595
using library facilities, 160
dec manipulator, 382–383, 1174
Decimal digits, isdigit(), 397
Decimal integer literals, 1077
Decimal number system, 381–383, 1077–1078
Deciphering (decryption), example, 969–974
Declaration operators, 1099
C++ and C, 1026
classes, 306
collections of. See Header files
definition, 51, 77, 257, 1098–1099, 1219
entities used for, 261
extern keyword, 259
forward, 261
grouping. See Namespaces
managing. See Header files
need for, 261
order of, 215
parts of, 1098
uses for, 1098
Decrementing ––, 97
pointer, 652
Deep copy, 636
for built-in types, 328
initializing objects, 327
need for, identifying, 641
#define, 1129
Definitions, 77, 258–259, 1219. See also Declarations
deallocating free store, 1094–1095
embedded systems, 932, 936–940
free-store deallocation, 598–600
in unary expressions, 1087
delete[], 599, 1087, 1094–1095
Delphi language, 831
Dependencies, testing, 1002–1003
Depth-first approach to programming, 6
deque, double ended queue, 1144
<deque>, 1133
Dereference/indirection
*, 594. See also Contents of
[], 118. See also Subscripting
Derivation, classes, 505
access control, 511
multiple inheritance, 1117
private bases and members, 511
protected bases and members, 511
public bases and members, 511
Destructors, 601–603, 1114–1115, 1219. See also Constructors
containers, 1148
default, 1119
freeing resources, 323, 700–702
generated, 603
Device drivers, 346
Dictionary examples, 123–125, 788
difference_type, 1147
digit, character class, 878, 1179
Digit, word origin, 1077
Dijkstra, Edsger, 827–828, 992
Direct expression of ideas, ideals, 811–812
distance(), 1142
Divide and assign /=, 67, 1090
Divide and conquer, 93
divides(), 1164
Domain knowledge, 934
Dot product. See inner_product()
double floating-point type, 63, 66–67, 78, 1099
Doubly-linked lists, 613, 725. See also list
fill color, 500
line visibility, 500
draw_lines() example. See also draw() example
Closed_polyline, 458
Open_polyline, 456
Polygon, 459
Rectangle, 465
Dynamic dispatch, 504–505. See also Virtual functions
Dynamic memory, 935-936, 1094. See also Free store (heap storage)
dynamic_cast, type conversion, 1095
exceptions, 1138
predictability, 932
Efficiency
vector range checking, 695
Einstein, Albert, 815
Elements. See also vector
numbering, 649
variable number of, 649
vs. Circle, 474
Ellipsis ...
arguments (unchecked), 1105–1106
catch all exceptions, 152
else, in if-statements, 102–104
coding standards, 975–977, 983
concurrency, 932
delete operator, 932
domain knowledge, 934
dynamic_cast, 932
exceptions, 932
fault tolerance, 930
hard real time, 931
maintenance, 929
new operator, 932
real-time constraints, 931
real-time response, 928
reliability, 928
resource leaks, 931
resource limitations, 928
soft real time, 931
Empty
empty(), is container empty? 1150
lists, 729
sequences, 729
statements, 101
Encapsulation, 505
Enciphering (Encryption), example, 969–974
end()
iterator, 1148
vector, 722
End of file
file streams, 366
I/O error, 355
stringstream, 395
End of input, 124
End of line $ (in regular expressions), 873, 1178
Ending programs. See Termination
endl manipulator, 1174
ends manipulator, 1174
English grammar vs. programming grammar, 193–194
enum, 318–321, 1042. See also Enumerations
Enumerations, 318–321, 1107–1108
enumerators, 318–321, 1107–1108
Equality operators, expressions, 1088
equal_to(), 1163
erase()
errno, error indicator, 918–919, 1182
passing multiple strings, 152
Error diagnostics, templates, 683
Error handling. See also Errors; Exceptions
% for floating-point numbers, 230–231
files fail to open, 389
GUIs, 576
hardware replication, 934
I/O errors. See I/O errors
I/O streams, 1171
monitoring subsystems, 935
predictable errors, 933
recovering from errors, 239–241
resource leaks, 934
self-checking, 934
STL (Standard Template Library), 1137–1138
transient errors, 934
vector resource exceptions, 702
Error messages. See also Reporting errors; error() example; runtime_error
templates, 683
writing your own, 142
Errors, 1219. See also Debugging; Testing
classifying, 134
compile-time, 48–50, 134, 136–137
detection ideal, 135
incomplete programs, 136
poor specifications, 136
recovering from, 239–241. See also Exceptions
sources of, 136
undeclared identifier, 258
unexpected arguments, 136
unexpected input, 136
unexpected state, 136
Errors, run-time, 134, 140–142. See also Exceptions
callee responsibility, 143–145
caller responsibility, 142–143
hardware violations, 141
Estimating development resources, 177
Examples
calculator. See Calculator example
Date. See Date example
deleting repeated words, 71–73
enciphering (encryption), 969–974
finding largest element, 713–716, 723–724
GUI (graphical user interface), 565–569, 573–574, 576–577
intrusive containers, 1059–1065
Lines_window, 565–569, 573–574, 576–577
reading a single value, 359–363
reading a structured file, 367–376
TEA (Tiny Encryption Algorithm), 969–974
vector. See vector example
Widget manipulation, 565–569, 1213–1216
writing a program. See Calculator example
<exception>, 1135
Exceptions, 146–150, 1125–1126. See also Error handling; Errors
bounds error, 149
C++ and C, 1026
catch, 147, 239–241, 1125–1126
destructors, 1126
embedded systems, 932
error messages, printing, 150–151
failure to catch, 153
GUIs, 576
narrow_cast example, 153
off-by-one error, 149
RAII (Resource Acquisition Is Initialization), 1125
stack unwinding, 1126
standard library exceptions, 1138–1139
terminating a program, 142
truncation, 153
type conversion, 153
uncaught exception, 153
user-defined types, 1126
vector range checking, 693–694
vector resources. See vector
Executing a program, 11, 1200–1201
exit(), terminating a program, 1194–1195
explicit constructor, 642–643, 1038
constant expressions, 1093
debugging, 161
grouping (), 95, 867, 873, 876
magic constants, 96, 143, 232–234, 723
mixing types, 99
non-obvious literals, 96
operator precedence, 95
order of operations, 181
precedence, 1090
preserving values, 1091
scope resolution, 1086
usual arithmetic conversions, 1092
Expression statement, 100
Extracting text from files, 856–861, 864–865
f/F suffix, 1079
fail() stream state, 355, 1171
Falling through end of functions, 274
false, 1038
Fault tolerance, 930
Feedback, programming, 36
binary I/O, 391
close(), 352
converting representations, 374–376
modes, 1186
open(), 352
opening files. See Opening files
reading. See Reading files
writing. See Writing files
Files, 1219. See also File I/O
opening and closing, C-style I/O, 1186
fill(), 1157
fill_n(), 1157
Fill color example, 462–465, 500
associative container operations, 1151
nonmodifying sequence algorithms, 1153
find_end(), 1153
find_first_of(), 1153
Finding. See also Matching; Searching
associative container operations, 1151
elements, 758
fixed format, 387
% remainder (modulo), 201
assigning integers to, 892–893
assigning to integers, 893
conversions, 1092
fixed format, 387
general format, 387
integral conversions, 1091–1092
mantissa, 893
and real numbers, 891
rounding, 386
scientific format, 387
truncation, 893
float type, 1099
FLTK (Fast Light Toolkit), 418, 1204
code portability, 418
current style, obtaining, 500
downloading, 1204
fill, 465
in graphics code, 436
installing, 1205
outlines, 465
rectangles, drawing, 465
testing, 1206
waiting for user action, 559–560, 569–570
flush manipulator, 1174
Fonts for Graphics example, 468–470
vs. while, 122
Ford, Henry, 806
Formal arguments. See Parameters
Formatting. See also C-style I/O; I/O streams; Manipulators
See also C-style I/O, 1050–1054
See also I/O streams, 1172–1173
See also Manipulators, 1173–1175
whitespace, 397
array indexing, 899
complex, 920
subscripting, 899
Forward declarations, 261
Fragmentation, embedded systems, 936, 937
free(), deallocate, 1043–1044, 1193
and destructors. See Destructors
garbage collection, 600
object lifetime, 1085
Freeing memory. See Deallocating memory
from_string() example, 853–854
front(), first element, 1149
front_inserter(), 1162
fstream(), 1170
<fstream>, 1134
Fully qualified names, 295–297
Function example, 443, 525–528
Function, 47, 113–117. See also Member functions
accessing class members, 1111
arguments. See Function arguments
in base classes, 504
calling, 1103
debugging, 160
definition, 113–115, 272, 1219
falling through, 274
formal arguments. See Function parameter (formal argument)
friend declaration, 1111
generic code, 491
global variables, modifying, 269
graphing. See Function example
linkage specifications, 1106
naming. See Namespaces
nesting, 270
organizing. See Namespaces
overloading, 321–323, 526, 1026
overload resolution, 1104–1105
parameter, 115. See also Function parameter (formal argument)
pure virtual, 1221
requirements, 153. See also Pre-conditions
return, 113–115, 272–273, 1103
standard mathematical, 528, 1181–1182
types as parameters. See Template
virtual, 1034–1036. See also Virtual functions
Function activation record, 287
Function argument. See also Function parameter (formal argument); Parameters
formal. See Parameters
naming, 273
omitting, 273
passing. See Function call
Function call, 285
call stack, 290
expression() call example, 287–290
function activation record, 287
history of, 820
() operator, 766
pass by const reference, 276–278, 281–284
pass by non-const reference, 281–284
recursive, 289
stack growth, 287–290. See also Function activation record
temporary objects, 282
Function-like macros, 1056–1058
Function member
same name as class. See Constructors
() function call operator, 766
adaptors, 1164
arithmetic operations, 1164
parameterization, 767
Function parameter (formal argument)
... ellipsis, unchecked arguments, 1105–1106
pass by const reference, 276–278, 281–284
pass by non-const reference, 281–284
temporary objects, 282
unused, 272
parameterized functions, 682–683
Functional cast, 1095
Functional programming, 823
Fused multiply-add, 904
Gadgets. See Embedded systems
Garbage collection, 600, 938–939
gcount(), 1172
general format, 387
general manipulator, 385
generate(), 1157
generate_n(), 1157
Generic code, 491
Generic programming, 682–683, 816, 1219
Geometric shapes, 427
get(), 1172
getline(), 395–396, 851, 855, 1172
gets(), 1052
C++ alternative >>, 1053
dangerous, 1052
scanf(), 1190
get_token() example, 196
Global variables
functions modifying, 269
order of initialization, 292–294
Going out of scope, 268–269, 291
good() stream state, 355, 1171
GP. See Generic programming
Grammar example
alternation, patterns, 194
Expression example, 197–200, 202–203
repetition, patterns, 194
rules vs. tokens, 194
sequencing rules, 195
terminals. See Tokens
Graph example. See also Grids, drawing
Graphical user interfaces. See GUIs (graphical user interfaces)
Graphics, 412. See also Graphics example; Color example; Shape example
encoding, 480
filling shapes, 431
formats, 480
geometric shapes, 427
line style, 431
selecting a sub-picture from, 480
user interface. See GUIs (graphical user interfaces)
GUI system, giving control to, 423
Point.h, 444
Simple_window.h, 444
wait_for_button(), 423
Window.h, 444
Graphics example, design principles
access control. See Access control
class diagram, 505
data modification access, 492–493
generic code, 491
inheritance, interface, 513–514
inheritances, implementation, 513–514
object-oriented programming, benefits of, 513–514
width/height, specifying, 490
Graphics example, GUI classes, 442–444. See also Graphics example, interfaces
Button, 443
In_box, 443
Menu, 443
Out_box, 443
Graphics example, interfaces, 442–443. See also Graphics example, GUI classes
Color, 450
Polygon, 427–428, 458–460, 497
Rectangle, 428–431, 460–465, 497
Shape, 444–445, 449, 493–494, 513–514
Graphing data example, 538–546
Graphing functions example, 520–524, 532–537
greater(), 1163
Greater than or equal >=, 1088
greater_equal(), 1163
Green marginal alerts, 3
Grids, drawing, 448–449, 452–455
Grouping regular expressions, 867, 873, 876
Guidelines. See Ideals
GUIs (graphical user interfaces), 552–553. See also Graphics example, GUI classes
callback implementation, 1208–1209
controls. See Widget example
coordinates, computer screens, 419–420
error handling, 576
examples, 565–569, 573–574, 576–577
exceptions, 576
FLTK (Fast Light Toolkit), 418
layers of code, 557
portability, 418
toolkit, 418
vector of references, simulating, 1212–1213
wait_for_button() example, 559–560
waiting for user action, 559–560, 569–570
Widget example, 561–569, 1209–1210, 1213–1216
Window example, 565–569, 1210–1212
GUI system, giving control to, 423
.h file suffix, 46
Hardware replication, error handling, 934
Hardware violations, 141
Hashed container. See unordered_map
Hashing, 785
Hash tables, 785
Hash values, 785
declarations, managing, 264
definitions, managing, 264
including in source files, 264–266, 1129
multiple inclusion, 1059
Headers. See Header files
Heap algorithm, 1160
Heap memory, 592, 935–936, 1084, 1160. See also Free store (heap storage)
Hejlsberg, Anders, 831
“Hello, World!” program, 45–47
Helper functions
== equality, 333
!= inequality, 333
Date example, 309–310, 332–333
namespaces, 333
validity checking date values, 310
hex manipulator, 382–383, 1174
Hexadecimal digits, 397
Hexadecimal number system, 381–383, 1077–1078
Hiding information, 1220
Hyperbolic cosine, cosh(), 918
Hyperbolic sine, sinh(), 918, 1182
Hyperbolic tangent, tanh(), 917
bad() stream state, 355
end of file, 355
eof() stream state, 355
error handling, 1171
fail() stream state, 355
good() stream state, 355
ios_base, 357
stream states, 355
unexpected errors, 355
>> input operator, 855
<< output operator, 855
cerr, standard error output stream, 151–152, 1169, 1189
cin standard input, 347
class hierarchy, 855, 1170–1171
cout standard output, 347
error handling, 1171
get(), 855
getline(), 855
header files, 1134
input operations, 1172
iostream library, 347–349, 1168–1169
istringstream, 1170
output operations, 1173
standard manipulators, 382, 1173–1174
standard streams, 1169
states, 1171
stream behavior, changing, 382
stream buffers, streambufs, 1169
stream modes, 1170
string, 855
throwing exceptions, 1171
unformatted input, 1172
IBM, 823
Ichbiah, Jean, 832
IDE (interactive development environment), 52
bottom-up approach, 811
class interfaces, 323
correct approaches, 811
correctness, 810
definition, 1219
direct expression of ideas, 811–812
efficiency, 810
importance of, 8
KISS, 815
maintainability, 810
performance, 810
on-time delivery, 810
top-down approach, 811
Identifiers, 1081. See also Names
reserved, 75–76. See also Keywords
imag(), imaginary part, 920, 1183
Images. See Graphics
Imaginary part, 920
Immutable values, class interfaces, 330–332
Implementation, 1219
programs, 36
Implementation-defined feature, 1075
In-class member definition, 1112
#include, 46, 264–266, 1128–1129
Include guard, 1059
includes(), 1159
Including headers, 1129. See also #include
iterators, 721, 750, 1140–1141
Indenting nested code, 271
Inequality != (not equal), 67, 1088, 1101
containers, 1151
helper function, 333
Infinite loop, 1219
Information hiding, 1220
Information processing, 32
Inheritance
class diagram, 505
definition, 504
history of, 834
multiple, 1117
pointers vs. references, 612–613
{} initialization notation, 83
menus, 571
Token example, 184
initializer_list, 630
inline, 1037
Inline
functions, 1026
member functions, 316
inner_product(), 759. See also Dot product
matrices, 904
multiplying sequences, 1184
inplace_merge(), 1158
Input, 60–62. See also Input >>; I/O streams
calculator example, 179, 182, 185, 201–202, 206–208
case sensitivity, 64
cin, standard input stream, 61
dividing functions logically, 359–362
files. See File I/O
individual characters, 396–398
istringstream, 394
newline character n, 61–62, 64
separating dialog from function, 362–363
stringstream, 395
tab character , 64
whitespace, 64
Input >>, 61
case sensitivity, 64
formatted input, 1172
multiple values per statement, 65
user-defined, 365
whitespace, ignoring, 64
Input/output, 347–349. See also Input; Output
C++ and C. See stdio
computation overview, 91
device drivers, 346
errors. See I/O errors
files. See File I/O
formatting. See Manipulators; printf()
irregularity, 380
natural language differences, 406
regularity, 380
streams. See I/O streams
strings, 855
Input prompt >, 223
Inputs, testing, 1001
Input streams, 347–349. See also I/O streams
insert()
map container, 782
inserter(), 1162
Inserting
Installing
FLTK (Fast Light Toolkit), 1205
Visual Studio, 1198
Instantiation, templates, 681, 1123–1124
int, integer type, 66–67, 78, 1099
Integers, 77–78, 890–891, 1220
assigning floating-point numbers to, 893
assigning to floating-point numbers, 892–893
largest, finding, 917
literals, 1077
smallest, finding, 917
Integral conversions, 1091–1092
Integral promotion, 1091
Interactive development environment (IDE), 52
Interface classes. See Graphics example, interfaces
Interfaces, 1220
classes. See Class interfaces
user. See User interfaces
internal manipulator, 1174
Intrusive containers, example, 1059–1065
Invariants, 313–314, 1220. See also Post-conditions; Pre-conditions
assertions, 163
default constructors, 641
documenting, 815
invention of, 828
Polygon example, 460
Invisible. See Transparency
<iosfwd>, 1134
iostream
buffers, 406
C++ and C, 1050
exceptions, 1138
Irregularity, 380
is_open(), 1170
isalnum() classify character, 397, 1175
isalpha() classify character, 247, 397, 1175
iscntrl() classify character, 397, 1175
isdigit() classify character, 397, 1175
isgraph() classify character, 397, 1175
islower() classify character, 397, 1175
isprint() classify character, 397, 1175
ispunct() classify character, 397, 1175
isspace() classify character, 397, 1175
>>, user-defined, 365
connecting to input device, 1170
file I/O, fstream, 349–354, 1170
get(), get a single character, 397
stringstreams, 395
unformatted input, 395–396, 1172
using together with stdio, 1050
<istream>, 1134, 1168–1169, 1173
istream_iterator type, 790–793
istringstream, 394
isupper() classify character, 397, 1175
isxdigit() classify character, 397, 1175
Iteration. See also Iterators
control variables, 110
definition, 1220
linked lists, 727–729, 737–741
strings, 851
through values. See vector
iterator, 1147
Iterators, 721–722, 1139–1140, 1220. See also STL iterators
bidirectional iterator, 752
empty list, 729
forward iterator, 752
input iterator, 752
output iterator, 752
vs. pointers, 1140
random-access iterator, 752
sequence of elements, 1140–1141
iter_swap(), 1157
Japanese age distribution example, 538–539
Kernighan, Brian, 838–839, 1022–1023
key_comp(), 1152
key_compare, 1147
key_type, 1147
Key, value pairs, containers for, 776
Keywords, 1037–1038, 1081–1082
KISS, 815
Knuth, Don, 808
l/L suffix, 1077
l, “lowercase character,” regex, 873, 1179
L, “not lowercase character,” regex, 874, 1179
Label
of statement, 1096
Largest integer, finding, 917
Laws of optimization, 931
Layers of code, GUIs, 557
Leaks, memory, 598–600, 601–605, 937
Leap year, 309
left manipulator, 1174
Legal programs, 1075
Length of strings, finding, 851, 1046, 1176
less(), 1163
Less than <, 1088
Less than or equal <=, 67, 1088
less_equal(), 1163
Letters, identifying, 247, 397
lexical_cast, 855
Lexicographical comparison
<= comparison, 1176
< comparison, 1176
>= comparison, 1176
> comparison, 1176
< comparison, 851
C-style strings, 1046
lexicographical_compare(), 1162
Libraries, 51, 1220. See also Standard library
role in debugging, 160
uses for, 177
Lifetime, objects, 1085–1086, 1220
Limit macros, 1181
Linear equations example, 908–914
classic_elimination(), 910–911
Line comment //, 45
vs. Lines, 448
vs. Line, 448
Lines (graphic), drawing. See also Graphics; draw_lines()
visibility, 500
Lines (of text), identifying, 736–737
Lines_window example, 565–569, 573–574, 576–577
Link-time errors. See Errors, link-time
Linkage convention, C, 1033
Linkage specifications, 1106
Linked lists, 725. See also Lists
Linking programs, 51
Lint, consistency checking program, 836
{} initialization notation, 83
back(), 737
referencing last element, 737
sequence containers, 1144
subscripting, 727
<list>, 1133
containers, 1150
empty, 729
getting the nth element, 615–617
inserting elements, 615–617, 742–745
links, examples, 613–615, 620–622, 726
decimal integer, 1077
in expressions, 96
f/F suffix, 1079
floating-point, 1079
hexadecimal integer, 1077
integer, 1077
l/L suffix, 1077
magic constants, 96, 143, 232–234, 723
non-obvious, 96
null pointer, 0, 1081
octal integer, 1077
termination, debugging, 161
for types, 63
u/U suffix, 1077
unsigned, 1077
Local (automatic) objects, lifetime, 1085
Local classes, nesting, 270
Local functions, nesting, 270
Local variables, array pointers, 658
Locale, 406
<locale>, 1135
Logic errors. See Errors, logic
Logical operations, 1094
logical_and(), 1163
logical_not(), 1163
logical_or(), 1163
Logs, graphing, 528
examples, parser, 200
Lovelace, Augusta Ada, 832
lower_bound(), 796, 1152, 1158
Lower case. See Case (of characters)
Lucent Bell Labs, 838
3.20.224.107