+ (addition operator), 58
& (address-of operator), 178, 181, 185, 200
= (assignment operator), 36, 64, 76, 359–367
* (asterisk), 185–186, 189, 477
+ (concatenation operator), 51, 291
* (dereferencing operator), 190
/ (division operator), 58
\ (double backslashes), 385
// (double forward slashes), 20, 22
= (equal sign), 80
== (equality operator), 76, 445
> (greater than operator), 76
>= (greater than or equal to operator), 76
< (less than operator), 76
<= (less than or equal to operator), 76
. (membership operator), 289
% (modulus operator), 58
*/ (multiline comment), 20
/* (multiline comment), 20
* (multiplication operator), 39, 58, 292
!= (not equal to operator), 76, 80
|| (or operator), 76
<< (overloaded assignment operator), 297–300, 362–367
| (pipe character), 129
:: (scope resolution operator), 213, 216, 289
; (semicolon), 10, 11, 12, 395
- (subtraction operator), 58
?: (ternary operator), 72–75, 289
~ (tilde), 226
_ (underscore character), 35, 395
{ } (curly braces)
code blocks, 164
nested control structures, 87
source file creation, 4
switch conditional, 85
< > angle brackets, 13, 184, 373, 380
” (double quotation mark) character, 48, 494
’ (single quotation mark) character, 48, 494
./ operator, 14
>> operator, 300
About.com Web site, 491
abs() function, 59
absolute values, 59
abstract methods, 283–287
aCar structure, 459
access control, 249–253
ADC (Apple Developer Connection), 27, 485
addition operator (+), 58
add() method, 288
addresses
arrays, 190
described, 176
incrementing, 191
memory blocks, 185
passing to functions, 200–206
stored in pointers, 183–185, 189, 193
vs. pointers, 181
addresses, computer, 176, 177–180
address-of operator (&), 178, 181, 185, 200
a.exe file, 7
aggregation, 243
alignment, 177
angle brackets < >, 13, 184, 373, 380
Anjuta DevStudio IDE, 486
a.out file, 7
append() function, 449
Apple Developer Connection (ADC), 27, 485
Apple Developer Tools, 27, 28, 485
applications
command-line arguments in, 473–477
compiling, 6–9
crashing, 372
creating, 2
executing. See execution
invoked from command-line, 14, 473
keeping open, 16–17
pausing execution of, 16–17, 26
printing values, 38–40
purpose of, 29
run-time errors, 317–319
stopping, 98
testing, 319
writing in C++, 1–3
area() function, 218
argc (argument count), 473–474
argument count (argc), 473–474
argument vector (argv), 473–475
arguments
command-line, 473–477
considerations, 444
default values, 149–153
multiple, 143
optional, 149–153
required, 148
vs. parameters, 148
argv (argument vector ), 473–475
arithmetic operations, 58–63. See also calculations; numbers
cmathheader file, 59
comparison operators, 76–80
fractions, 288, 293–295, 386–387
multiplication, 39, 58, 288, 292
operator overloading, 294, 360–367
overview, 58–59
performing, 60–63
arithmetic operators, 58–63, 88–91
arithmetic, pointer, 190–191, 193
array elements
accessing with loops, 171, 175
accessing with pointers, 190
calling member functions for, 225
array subscription operator [ ], 349
arrays
addresses, 190
advanced concepts, 175
allocating, 349–353
considerations, 432
as containers, 432
data types, 193
deleting, 350
described, 170
elements in. See array elements
for loops and, 98
multidimensional, 175
object, 225
passing to functions, 477
pointers to, 190–193
printing values, 175
size of, 170, 175, 351–353, 434
subarrays, 175
vs. pointers, 349–350
vs. vectors, 198
working with, 170–175
ASCII character chart, 493–494
ASCII files, 458
assert() function, 326–331
assert.h library, 326
assignment operator (=), 36, 63, 76, 359–367
asterisk (*), 185–186, 189, 477
attributes
access levels, 249–253
ambiguity, 232–235
in classes, 208–211
declaring, 210
inherited, 253
static, 268–274
auto storage class, 406
automatic variables, 168, 406, 412
(backspace character), 19, 48, 494
backspace character (), 19, 48, 494
base classes, 238, 243, 244, 310, 337, 348
base constructor, 245–247
basename, 5
BBEdit, 3
big endian machines, 466
binary files, 458–472
C-style strings, 459
random access to data in, 467–472
reading from, 464–466
vs. plain-text files, 458
writing to, 458–463
binary trees, 432
body, function, 2
bool data type, 55
Boolean values, 131, 214, 219, 228, 321
branching structure, 64
buffers, 107
C++ code
basic syntax, 2–5
comments in. See comments
compiling. See compiling
generic, 415
implementation, 388
interface, 388
multiple lines in, 12
organizing in folders, 4
templates. See templates
white space, 18–19
C++ code block, 164
C++ escape sequences, 48
.C extension, 5
.c extension, 5
C++ FAQ Lite site, 490
C++ language
basics, 1–28
case sensitivity of, 2
newsgroups, 491
paradigms, 415
printing text in, 11–13
resources, 489–494
Web sites, 490–491
C preprocessor, 10, 13, 55, 394–397
C++ programs. See applications; code
C++ Standard, 433
C++ Standard Library, 433, 440–442, 441, 442
C++ tools, 479–487
Apple Developer Tools, 27, 28, 485
command-line tools, 27
Dev-C++. See Dev-C++ for Windows
overview, 3
trigonometric tools, 59
Unix tools, 486
Xcode. See Xcode
calculations. See also arithmetic operations
formatting, 42–43
interest rate formula, 59, 61–62
loan calculation formulas, 60–63
mortgage calculation formula, 60–63, 68–70
sensitive, 40
temperature conversion, 108–110, 114–117
capacity() method, 457
carriage character ( ), 48
casting operators, 47, 182. See also type casting
casts. See type casts
catch block, 337
catch statements, 332
.cc extension, 5
C/C++ Style Guides, 491
cd command, 8
changeVar() function, 199–200, 203–204
character input, 100–104
character variables, 49–50
characters. See also text
ASCII character chart, 493–494
deleting, 105–107
introduction to, 48–50
reading single character, 100–104
in strings, 154
validating, 126
cin (console in), 16–17
cin objects, 100, 104, 105, 108–110, 122
cin.bad() call, 123
cin.fail() call, 123
cin.get() call, 16–17
class keyword, 416
class templates, 422–427
classes
access control, 249–253
adding attributes to, 208–209
adding methods to, 212–216
adding static members to, 270–274
attributes in, 208–211
base, 238, 243, 244, 310, 337, 348
constants in, 211
creating objects from, 217–220
derived, 243
design of, 231
friend, 261–266
hierarchy, 238–239
inheritance. See inheritance
instances, 217
instantiating, 431
methods in, 211
multiple objects from, 217
names, 208, 209, 222, 262, 422
pointers to, 344–348
protection, 249
storage, 406
variables in, 210
climits header file, 320
close() function, 133
cmath library, 59
cmd utility, 7
Cocoa technology, 27
code
basic syntax, 2–5
comments in. See comments
compiling. See compiling
generic, 415
implementation, 388
interface, 388
multiple lines in, 12
organizing in folders, 4
templates. See templates
white space, 18–19
code block, 164
coercion technique, 44
command line, 7–9, 14, 476, 477
command-line arguments, 473–477
command-line tools, 27
comments
adding, 20–22
control structures, 87
format of, 20
header files, 381–382
importance of, 32
multiline, 20–22
compare() function, 445
comparison operators, 76–80
compiler directives, 13
compiler warnings, 4, 34, 46–47, 318
compilers
cmd utility, 7
g++. See g++ compiler
header files, 388
implementation files, 388–391
Terminal application, 7
compile-time check, 279
compile-time errors, 6, 314–316
compile-time type, 279
compiling
entire application, 387
multiple files, 392–393
procedure for, 6–9
single file, 387
while executing, 15
comp.lang.c++ newsgroup, 491
composition, 243
computer memory, 176–180
concatenation operator (+), 51, 291
conditional directives, 395
conditionals
else clause, 68–71
if, 64–67
reversing values in, 80
console in (cin), 16–17
console input. See cin
console out (cout), 10, 38, 41–43, 49
const char * type, 337
const keyword, 54
constant definitions, 394–397
constant float, 54
constants
assigning values to, 55
in classes, 211
defining parameters as, 206
defining with preprocessor directives, 55
described, 54
introduction to, 54–55
static, 211
using, 54–55
const_cast data type, 47
constructors
access control, 250–251
base, 245–247
declaring, 228
default, 223
described, 221
empty, 223
exceptions and, 337
inherited, 243–248
overloaded, 224
size of, 248
vs. destructors, 226
containers, 432–439
continue statement, 98
copy constructor, 223, 359–367
cout (console out), 10, 38, 41–43, 49
cplusplus.com Web site, 490
.cpp files, 388
Cprogramming.com Web site, 491
cross-platform issues, 13, 132. See also specific platform
cstddef header file, 343
c_str() function, 459
C-style strings, 459
ctype library, 126
curly braces { }
code blocks, 164
nested control structures, 87
source file creation, 4
switch conditional, 85
.cxx extension, 5
.dat extension, 460
data, 467–472
Data Display Debugger (DDD), 487
data types. See also specific data types
arrays and, 193
complex, 169–206
described, 55
enumeration, 206
signed, 30
size of, 45
DDD (Data Display Debugger), 487
debugging. See also errors
assert() function, 326–331
catching exceptions, 332–337
compile-time errors, 6, 314–316
with Gnu Debugger, 487
multiline comment type and, 22
printing variable values, 40, 318
run-time errors, 317–319
techniques for, 314–319
declaring variables, 30–35, 37
decrement operators, 88–91
delete [ ] statement, 350–352, 376
delete keyword, 275–278
delete statement, 341–342, 347, 348, 376–378
deleting
arrays, 350
buffers, 107
characters, 105–107
dereferencing operator (*), 190
dereferencing pointers, 185–186, 189, 194, 200, 275
dereferencing structures, 194
destructors
automatically generated, 231
creating, 227–231
declaring, 228
defining, 226–231
exceptions and, 337
inherited, 244–248
names, 226
vs. constructors, 226
Dev-C++ for Windows, 480–484
adding g++ compiler, 484
configuring, 482
customizing, 483–484
described, 480
Gnu Debugger, 487
included files, 393
installing, 480–481
running for first time, 482
specifying command-line arguments in, 477
using, 24–26
Dev-C++ Resource Site, 26
directives
compiler, 13
conditional, 395
creating conditionals, 395
defining constants with, 55
semicolons and, 395
division operator (/), 58
DMCInsights.com Web site, 491
dot syntax, 195
double quotation mark (”) character, 48, 494
double forward slashes (//), 20, 22
double type, 493
double variables, 417
dynamic arrays, 349–353, 424–425
dynamic memory, 339–378
array allocation, 349–353
assignment operator, 359–367
copy constructor, 359–367
described, 339
dynamic objects and, 372–375
object allocation, 344–348
requesting, 342–343
scope and, 377
static objects and, 368–375
vs. static memory, 340–343
dynamic object type casts, 372–375
dynamic_cast data type, 47, 373–375
dynamic_cast operator, 182, 372–375
E notation, 31
Eclipse IDE, 486
#elif directive, 395
#else directive, 395
else if clause, 68–71
empty() function, 448
#endif directive, 395
enum keyword, 206
enumeration, 206
eof() function, 122
equal sign (=), 80
equality operator (==), 76, 445
erase() function, 457
error codes, 320–325
errors. See also debugging; troubleshooting
assert() function, 326
binary files, 463
case sensitivity and, 2
casting operators and, 182
catching exceptions, 332–337
namespaces, 400
“off-by-one,” 175
programmers and, 326
return codes, 321–325
templates, 421
undefined function, 220
unmatched pointer types, 181
users and, 326
vector elements, 436
virtual methods and, 283
Euclid’s algorithm, 290
exception file, 337
exception handling, 332–337
exceptions
catching, 332–337
constructors and, 337
destructors and, 337
managing, 337
objects as, 337
run-time errors and, 332
use of, 337
vs. return statements, 325
execution
compiling and executing in one step, 15
Mac OS X systems, 14–15
stopping, 158
Unix systems, 14–15
Windows systems, 14–15
exit statement, 98
exponential power, 59
extensions
.C, 5
.c, 5
.cc, 5
.cxx, 5
.dat, 460
determining, 446
.h, 13
header files, 13
.rtf, 3
searching for, 455
source files, 5
strings and, 455
substrings and, 446–448
.txt, 460
external storage class, 406, 408, 409
f (new page) character, 494
factorial calculation, 92–97
factorial class, 321
factorial objects, 324
factorial values, 155–157, 320–325
factory functions, 355–357
factory methods, 357
fail() function, 122
fall-through situations, 102
false conditions, 64–70
comparison operators, 76
for loops, 96
ternary operator, 72–75
false value, 55
file output, 127–131
file scope, 408
files
adding white space to, 19
ASCII, 458
binary. See binary files
closing, 133
compiling. See compiling
creating, 3–5
extensions. See extensions
header. See header files
implementation, 388–391
included, 380–393
invalid name/path, 231
makefiles, 393
paths, 134, 231, 385, 387, 484
writing to, 128–131
find feature, 454–457
find _last_of() function, 454
Finder, 9
find_first_not_of() function, 454
find_first_of() function, 454
find_last_not_of() function, 454
fixed-point notation, 41
float variables, 417
floating-point numbers, 30, 31, 40, 41, 131
floats, equality of, 80
folders, 4
for loops, 96–98
formatting numbers, 41–43
forward declaration, 384
forward slash (/), 385
fractions, 288, 293–295, 386–387
friend classes, 261–266
“friends” concept, 211
fstream flags, 494
function templates, 417–421
functions, 137–168
allocating objects from, 355–357
body of, 2
contents of, 2
creating functions that return values, 154–159
creating functions that take arguments, 143–148
creating simple functions, 138–143
declaring, 216
defining, 137–142, 144–148, 216
described, 137
factory, 355–357
friends, 261
implementing, 139
multiple, 141
overriding, 161
passing addresses to, 200–206
passing arrays to, 477
passing values by reference, 203–206
passing values to, 199, 201–206
prototypes, 138, 139, 418–419, 421
recursive, 159
returning memory, 354–357
returning objects, 355–357
returning values, 3, 4, 154–159
static, 414
stopping execution of, 158
stored in memory, 180
throwing errors from, 337
undefined, 220
user-defined, 199–206
variables within, 164–165, 168
g++ compiler
basics, 6–9
compiling multiple files with, 392–393
Mac systems, 28
Windows systems, 484
gcd (greatest common divisor), 293
gcount() function, 107
GDB (Gnu Debugger), 487
get() function, 104
getline() function, 118–120, 132–136
getter methods, 274
global scope, 377, 398, 401, 404
global variables, 164–168, 377, 406, 410
Gnu Debugger (GDB), 487
good() function, 122, 127, 131
goto control structure, 87
graphical user interface (GUI), 3
greater than operator (>), 76
greater than or equal to operator (>=), 76
greatest common divisor (gcd), 293
GUI (graphical user interface), 3
.h extension, 13
hash mark (#), 394
hash tables, 432
header files
class inheritance and, 384
creating, 381–384
custom, 380–384
extension for, 13
importance of, 388
included, 380–393
linkage, 410
modifying, 396–397
names, 384
scope, 410
types of, 380–381
using directive and, 405
hexadecimal numbers, 178
hexadecimal values, 178
hierarchy, 238–239, 280, 302. See also inheritance
IDE (integrated development environment)
alternatives to, 393
Anjuta DevStudio IDE, 486
Eclipse IDE, 486
KDevelop IDE, 486
identifiers, 31, 128, 198, 398, 399
if conditionals, 64–67
#if directive, 395
#ifdef directive, 395
if-else if statement, 71
#ifndef directive, 395
ignore() function, 105–107, 123, 124
implementation, 388
implementation file, 388–391
implicit conversion, 44
#include directive, 13, 380, 394
included files, 380–393
increment operator, 88–91
incrementing pointers, 191
indention, code, 18, 19, 71, 87
indexes, 170, 175, 437–439, 439
infinite loops, 92, 98, 159, 472
infinity value, 95
inheritance, 237–266
access control, 249–253
attributes, 253
basic, 238–243
described, 237
destructors, 244–248
friend classes, 261–266
header files and, 384
methods, 253
multiple, 301–307
protecting members, 250–253
relationships, 243
virtual, 308–311
vs. composition, 243
inherited classes, 344–348
inline keyword, 153
inline notation, 429–431
inline templates, 428–431
input, 100–126
character, 100–104
discarding, 105–107
invalid, 110
multiple, 114–117
numeric, 108–110
reading file input, 132–136
reading in entire lines, 118–120
reading numeric input, 108–110
string, 111–113
unable to read in, 172
user, 111–113
input/output stream. See iostream
insert() function, 449
Insight Debugger, 487
integer variables, 183
integers. See also numbers
ASCII character chart, 493–494
calculations, 40
dividing, 58
overflow, 95
pointers to, 183
reading in, 172
returning factorial value, 155–157
type casting addresses as, 180
underflow, 95
unsigned, 351
vs. real numbers, 58
integrated development environment (IDE)
alternatives to, 393
Anjuta DevStudio IDE, 486
Eclipse IDE, 486
KDevelop IDE, 486
interest rate formula, 59, 61–62
Interface Builder, 28
interfaces, 28, 310, 388. See also base classes
INT_MAX value, 320
INT_MIN value, 320
ios::ate flag, 494
ios::binary flag, 494
ios::in flag, 494
ios::nocreate instruction, 131
ios::noreplace instruction, 131
ios::out flag, 494
iostream file, 10, 32, 104, 131
iostream header file, 382
ios::trunc flag, 494
isalnum() function, 126
isalpha() function, 126
isspace() function, 126
iterators, 437–440
KDevelop IDE, 486
length() function, 444
less than operator (<), 76
less than or equal to operator (<=), 76
cross-platform compatibility, 13
extra, 398
failure to include, 315
names, 433
third-party, 378
types of, 433
limits.h header file, 320
lines
multiple, 12
linker, 7
little endian machines, 466
loan calculation formulas, 60–63
local variables, 164–168, 276–278, 358, 412
logical operators, 76–80
long data types, 30
long double data types, 30, 31, 493
long int type, 493
loops
for, 96–98
accessing array elements with, 171, 175
increment/decrement operators, 91
Mac OS X systems
BBEdit, 3
case sensitivity and, 5
Cocoa technology, 27
compiling C++ from command line, 7–9
executing files, 14–15
file name restrictions, 5
g++ compiler, 28
Interface Builder, 28
Objective-C, 28
slashes and, 132
Terminal application, 7
TextEdit, 3
variable addresses, 180
Xcode. See Xcode
make utility, 393
makefiles, 393
mathematical operations. See arithmetic operations
member variables, 238–239
members. See also variables
access control, 250–251
bitwise copy of, 359
inherited, 253
protecting, 250–253
referring to, 195
static, 270–274
structures and, 194–195
values, 195
membership operator (.), 289
memory. See also dynamic memory
buffers, 107
characters and, 50
computer, 176–180
dynamic. See dynamic memory
fixed amount of, 339
freeing, 276, 277, 348, 371, 376–378
functions stored in, 180
pointers and, 176–177, 185, 189, 275
problems with, 341–343
requesting, 340
resetting, 341
returning for functions, 354–357
static, 340–343
memory addresses, 176–180
memory blocks, 37, 185–190, 340–343
memory leaks
avoiding, 376–378
creating, 341
described, 376
factory functions and, 357
missing delete statements, 341
memory scope, 377
methods
abstract, 283–287
access levels, 249–253
calling other methods, 216–217
creating, 213–215
factory, 357
getter, 274
names, 222
overloading, 258–260
returning memory, 354–357
setter, 274
modularization, 379
modulus operator (%), 58
mortgage calculation formula, 60–63, 68–70
multidimensional arrays, 175
multiline comments type (/* */), 20, 21, 22
multiplication operations, 39, 58, 288, 292
multiplication operator (*), 39, 58, 292
(newline) character, 18, 19, 33, 48, 110, 494
name attribute, 308–311
namespace keyword, 398, 399, 401
namespaces, 398–405
accessing items in, 404
alias to, 401
creating, 398–403
custom, 405
debugging and, 316
declaring, 399–400
names, 400
using, 404–405
natural boundaries, 177
negative numbers, 290
new keyword, 275–276
new page (f) character, 494
new statement, 340–343, 347, 351, 376, 378
newline character ( ), 18, 19, 33, 48, 110, 494
newsgroups, 491
nonvolatile designation, 182
normalization, 290
not equal to operator (!=), 76, 80
Notepad, 3
numbers. See also arithmetic operations
absolute values, 59
decimal, 30, 31, 41–42, 493–494
floating-point, 30, 31, 40, 41, 131
formatting, 41–43
hexadecimal, 178
infinity value, 95
integers. See integers
negative, 290
overflow, 95
prime, 159
rational, 288–289
real vs. integers, 58
returning, 154
square root of, 59
static, 54
numeric data types, 30–31, 493
numeric input, 108–110
numeric variables, 41–47
-o flag, 17
Objective-C, 28
object-oriented paradigm, 415
object-oriented programming (OOP), 267–311
<< operator, 295–300
abstract methods, 283–287
example of, 231
multiple inheritance, 301–307
object-oriented paradigm, 415
overloading operators, 288–295
polymorphism, 287
static attributes, 268–274
static methods, 268–274
virtual inheritance, 308–311
virtual methods, 275–282
vs. procedural programming, 211
objects, 207–235
arrays of, 225
cin, 100, 104, 105, 108–110, 122
classes. See classes
creating, 217–220, 224, 345–348
dynamic, 372–375
as exceptions, 337
factorial, 324
instances, 361
relationships between, 243
returning, 355–357
static, 368–375
using, 217–220
vs. structures, 211
ofstream file, 127–131
ofstream object, 224
OOP (object-oriented programming), 267–311
<< operator, 295–300
abstract methods, 283–287
example of, 231
multiple inheritance, 301–307
object-oriented paradigm, 415
overloading operators, 288–295
polymorphism, 287
static attributes, 268–274
static methods, 268–274
virtual inheritance, 308–311
virtual methods, 275–282
vs. procedural programming, 211
open() function, 131
operating systems. See also specific operating systems
binary files, 458
cross-platform issues, 13, 132
file name restrictions, 5
slashes and, 132
operator<<() function, 295–300
operator+() method, 292
operators. See also specific operators
casting, 182
comparison, 76–80
decrement, 88–91
increment, 88–91
logical, 76–80
ternary, 72–75
or operator (||), 76
output, file, 127–131
overflow, 95
overloaded assignment operator (<<), 297–300, 362–367
overloaded items
constructors, 224
methods, 258–260
overriding functions, 161
overriding methods, 254–257, 260
padding, 43
parameters
defining as constants, 206
formatting, 38
string, 420
vs. arguments, 148
parent classes, 238
( ) parentheses
arguments and, 139
If conditionals, 64
logical operators, 76
pointer cast, 369
pointers and, 184
precedence and, 81
type casts and, 374
parentheses ( )
arguments and, 139
If conditionals, 64
logical operators, 76
pointer cast, 369
pointers and, 184
precedence and, 81
type casts and, 374
paths, 134, 231, 385, 387, 484
pause command, 17
pipe character (|), 129
pointer arithmetic, 190–191, 193
pointer cast, 369
pointer types, 181, 185, 190, 203
pointer variables, 377
pointers
addresses stored in, 183–185, 189, 193
alignment, 177
array, 190–193
assigning values to, 181
assignment operators and, 362–367
to base class, 348
changing values with, 185–189
to classes, 344–348
copy constructors and, 362–367
declaring, 181
dereferencing, 185–186, 189, 194, 200, 275
finding addresses, 176, 177–180
incrementing, 191
to integers, 183
local variables and, 358
memory and, 176–177, 185, 189, 275
object allocation and, 344–348
returning, 358
to structures, 194
using, 183–184
values, 185, 186, 187, 188, 189
void, 189
vs. addresses, 181
vs. arrays, 349–350
vs. local variables, 276–278
working with, 176–193
polymorphism, 287
pop() method, 424, 426, 430–431
postfix increment/decrement operator, 88–90
pow() function, 59, 60, 61, 154
precision function, 41
prefix increment/decrement operator, 88–90
preprocessor directives, 10, 13, 55, 294–397
prime numbers, 159
printing
approval message, 65–70, 73, 75
array values, 170
print() method, 290, 293, 294, 297–298
private access level, 249, 252, 253, 261
private keyword, 211
problems. See errors; troubleshooting
procedural paradigm, 415
procedural programming, 211
programming
described, 29
programs. See applications
promptAnd Wait() function, 414
protected access level, 249, 252, 253, 261
protected keyword, 211
prototypes, 138, 139, 418–419, 421
public access level, 249, 252, 253, 261
push_back() function, 434
push() function, 424, 427, 430–431
quotation mark (”) character, 48, 494
quote mark (’) character, 48, 494
(carriage character), 48
(return) character, 494
Rational class, 288–300
rational numbers, 288–289
read() function, 464–466
recursive functions, 159
reference tables, 492–494
register storage class, 406
reinterpret_cast data type, 47, 184
reinterpret_cast operator, 182, 343, 372
“friends,” 261–266
to functions, 2
inheritance, 243
“is-a,” 301
linkage and, 407
between pointers/arrays, 191
rename() method, 262–265
reserve() function, 457
resources, 489–494
return ( ) character, 494
return codes, 321–325
return statements
including, 5
multiple, 158
name arrays and, 358
vs. exceptions, 325
returned values, 44
returnFactorial() function, 413
rfind() function, 454
Rich Text Format (.rtf), 3
RTF (Rich Text Format), 3
.rtf extension, 3
run-time errors, 317–319, 326, 332
scalar types, 190
scalar values, 169
scope
debugging and, 316
described, 164
linkage and, 406–414
memory, 377
scope resolution operator (::), 213, 216, 289
scripts
white space in, 18–19
searches, 454–457
seekp() function, 467
semicolon (;), 10, 11, 12, 395
setColor() method, 211
setSize() function, 215, 218, 222
setter methods, 274
setWeight() class, 211
setw() function, 43
short data types, 30
short int type, 493
SHRT_MAX value, 320
SHRT_MIN value, 320
signed integer types, 30
single quotation mark (’) character, 48, 494
size() function, 112, 154, 444
sort() algorithm, 440–442
source code. See code
source files
adding white space to, 19
creating, 3–5
extensions for, 5
SourceForge, 486
spaces, 43
sqrt() function, 59
square root, 59
stacks
adding values to, 427
automatic variables, 406
creating, 424–427
described, 423
removing values from, 427
size of, 425
storage classes, 406
template-based, 423
Standard C++ Library, 433, 436
Standard Template Library (STL), 415, 433
statements. See also specific statements
catch, 332
multiple lines, 12
on one line, 12
return. See return statements
static attributes, 268–274
static constants, 211
static functions, 414
static keyword, 343
static memory, 340–344
static methods, 268–274, 280, 414
static numbers, 54
static object type casts, 368–375
static storage class, 406, 409
static type cast, 368–371
static variables, 408, 412, 414
static_cast data type, 47
static_cast operator, 182, 372
STL (Standard Template Library), 415, 433
stop character, 106
storage classes, 406
streams, 10–13
string functions, 444
string input, 111–113
string type, 198
strings, 444–457
adding to, 449–453
allotted space for, 457
assigning values to, 51
comparing, 445
concatenation, 449
C-style, 459
described, 51
escape sequences, 494
introduction to, 51–53
length of, 53
removing characters from, 457
replacing part of, 450
returning number of characters in, 154
searching through, 454–457
substring creation, 445–448
translating into number types, 126
using, 51
strncpy() function, 459
strtod() function, 126
strtold() function, 126
strtol() function, 126
structure variables, 194–198
structures, 194–198
arrays of, 198
complex, 198
defining, 195–198
dereferencing, 194
described, 194
members and, 194–195
pointers to, 194
unions, 198
using, 195–198
vs. objects, 211
style guides, 491
subarrays, 175
subclass constructor, 245–248
subfolders, 4
substr() function, 446–448
substrings, 445–448
substr() method, 445
subtraction operations, 58, 292
subtraction operator (-), 58
swap() function, 201–205, 417–421
switch conditionals, 82–87, 98, 206
system header files, 380
T placeholder, 424
tables, reference, 492–494
tellg() function, 467, 468, 470
tellp() function, 467
templates, 415–442
basic syntax, 416–427
class, 422–427
containers, 432–439
creating code from, 421
described, 415
errors, 421
function, 417–421
inline, 428–431
iterators, 437–439
Standard Template Library, 433
vectors, 434–436
Terminal application, 7
ternary operator (?:), 72–75, 289
testing programs, 319
text. See also characters; input
reading in lines of, 118–120
Rich Text Format, 3
text editors, 2, 3, 23, 24, 32
TextEdit, 3
throw keyword, 332
throw statement, 333–334
tilde (~), 226
tools, 479–487
Apple Developer Tools, 27, 28, 485
command-line tools, 27
Dev-C++. See Dev-C++ for Windows
overview, 3
trigonometric tools, 59
Unix tools, 486
Xcode. See Xcode
toupper() function, 126, 450, 454
translation unit, 406, 407, 413
trigonometric tools, 59
trinary operator. See ternary operator
troubleshooting. See also debugging; errors
ambiguity problems, 161, 232, 233
arrays, 175
compiler warnings, 4, 34, 46–47, 318
function calls, 372
memory issues, 341–343
true conditions, 64–70
comparison operators, 76
for loops, 96
ternary operator, 72–75
while loops, 92–95
true value, 55
.txt extension, 460
type cast operator, 369–371
type casts
dynamic, 372–375
static, 368–375
type conversion, 44–47
typedef keyword, 206
UINT_MAX value, 320
Ulong_MAX value, 320
#undef directive, 397
underflow, 95
underscore character (_), 35, 395
unions, 198
Unix systems
case sensitivity and, 5
compiling C++ from command line, 7–9
executing files, 14–15
file name restrictions, 5
slashes and, 132
source file creation, 3
Terminal application, 7
unsigned int type, 493
unsigned integer types, 30
unsigned long int type, 493
unsigned short data types, 33
unsigned short int type, 493
users, 326
USHRT_MAX value, 320
utilities. See tools
validating input, 121–126, 318
validation functions, 145, 147, 320
values
absolute, 59
arguments, 149–153
assigning to array elements, 170, 175
assigning to character variables, 48–50
assigning to constants, 55
assigning to numeric variables, 36–37
assigning to pointers, 181
assigning to strings, 51
changing with pointers, 185–189
converting data types, 44–47
false, 55
functions that return, 154–159
hexadecimal, 178
members, 195
passing by address, 201–203
passing by reference, 203–206
passing to functions, 199, 201–206
pointers, 185, 186, 187, 188, 189
printing for arrays, 175
printing for variables, 39–40, 318
returning from functions, 3, 4
scalar, 169
swapping, 201–203
true, 55
unions, 198
variable declarations, 409
variable scope, 98, 164–168, 406
variables. See also members
alignment, 177
ambiguity, 232–235
assigning character values to, 48–50
assigning numeric values to, 36–37
in classes, 210
converting data types, 44–47
creating, 194
exchanging values of, 417
within functions, 164–165, 168
integer, 183
local, 164–168, 276–278, 358, 406, 412
non-static, 414
numeric, 41–47
returned values based on, 154
spaces in, 43
for string types, 51
structure, 194–198
swapping values in, 201–203
types of, 30–31
vs. pointers, 276–278
vectors
accessing members of, 438–439
adding elements to, 435
arrays and, 175
creating, 434
iterators and, 438–439
modifying element values, 436
retrieving items from, 435
types of, 434
vs. arrays, 198
working with, 434–436
virtual inheritance, 308–311
virtual keyword, 279
void pointer, 189
volatile designation, 182
wait application, 16–17
warnings
type casting and, 46
Web sites, 490–491
About.com, 491
Apple Developer Connection, 27, 485
C++ FAQ Lite, 490
C++ language, 490–491
cplusplus.com, 490
Cprogramming.com, 491
Dev-C++ Resource Site, 26
DMCInsights.com, 491
Windows Notepad, 3
Windows systems
adding g++ to system path, 484
case sensitivity and, 5
cmd utility, 7
compiling C++ from command line, 7–9
Dev-C++. See Dev-C++ for Windows
executing files, 14–15
file name restrictions, 5
g++ compiler, 484
slashes and, 132
variable addresses, 180
WordPad, 3
WordPad, 3
write() function, 458–463
Xcode
described, 485
Gnu Debugger, 487
help with, 485
included files, 393
installing, 485
obtaining, 27
specifying command-line arguments in, 477
using, 27–2