Thứ Hai, 10 tháng 2, 2014

Tài liệu Giáo trình C++ P1 docx


www.gameinstitute.com Introduction to C and C++ : Week 1: Page 5 of 42
Writing programs in machine language was both simple and complicated. It was simple because you were
working with just a handful of instructions and a slew of memory addresses at which data could be stored
and retrieved. But machine language was complicated because each program is nothing but numbers.
Some numbers represent instructions, some represent memory addresses, and some represent literal
values. As a result, writing, deciphering, and maintaining these programs was time consuming and
painstaking work. Humans just aren’t good at manipulating pages and pages of numbers.

The problem is that computers and humans speak very different languages. Forcing humans to speak the
native language of the machine, although necessary at one time, is very taxing for humans. In order to
write large, reliable, and easily upgradeable software systems, humans needed to design a better way to
communicate with the computer.

Today there are a slew of computer languages, all of which address the issue of human/machine
communication in its own way. In all cases these languages are more natural for human use due to the use
of abstraction. Even very detail-oriented languages, such as assembly language, use abstractions.
Assembly language provides human-readable names to be used for both instructions and data, abstracting
the underling numeric values. Other languages, such as Visual Basic, Java, C, and C++ also use
abstractions, but to a much higher degree.

The more abstract the language, the less the language is like machine language. Highly abstract languages
cater to the way that humans think, and not to the way that computers operate. With a modern language,
programmers don’t have manage numeric codes, but more importantly, are not limited to the commands
that the hardware provides. These languages allow new, complex instructions to be defined that are just as
easy to use as the native computer hardware instructions. Instead of being limited to commands such as
“copy”, “add”, and “multiply”, these languages can be extended to include very powerful and specific
commands such as “update database”, “fire weapons”, or “draw explosion”.

Computer hardware has gotten much, much faster. And computer languages have gotten much, much
more powerful. But, while computer hardware now provides millions of times more performance than
early hardware, it really hasn’t changed that much. It still uses very simple numeric instructions that
indicate operations such as “copy”, “add”, and “multiply”, and it still uses memory addresses to store and
retrieve data. How can languages have evolved to be so abstract when the underlying hardware remains
largely the same? The answer is that the computer now performs much more work than it used to.

With machine language, the program, or source code that the programmer wrote was exactly the same as
that which the computer executed. The source code was the program. With all other languages, the source
code is not the same as the instructions that the computer executes. Instead there is at least one step that is
required to convert source code into executable form. This is accomplished in one of two ways,
depending on the language being used.

Languages such as Java and early versions of Visual Basic, for example, are interpreted languages. This
means that in order for source code to be executed, an interpreter is required. These interpreters are
themselves programs—which are specialized to read source code and convert it into a set of operations
that are in turn executed by the hardware. Alternatively, languages such as C, C++, and modern versions
of Visual Basic are compiled languages. These languages require a program called a compiler that reads
source code and converts it into machine language.

Interpreted languages, because they require source code to be converted at runtime (at the time that
execution is to take place), is slower than the compiled equivalent. Compiled languages, by requiring that
the highly complex conversion process take place before execution, provide better runtime performance.


www.gameinstitute.com Introduction to C and C++ : Week 1: Page 6 of 42
In both cases, the computer is expected to perform extra steps to convert source code into something that
the computer understands. Now, instead of learning the computer’s native tongue, we write software in a
language that makes sense to us, and we leave the task of conversion to the computer. The computer does
more work than it used to, and humans do less. This arrangement works nicely because computers are
very good at the type of work that is required to convert source code to machine languages, and, because
computers are faster than ever, there is plenty of extra processing power for these conversions.

Nevertheless, it is not as though we are free to explain to the computer what we want in plain English. We
still must learn a computer language such as C++. And, while easier to understand than machine
language, understanding C++ takes some practice. Modern computer languages are a compromise
between machine language and truly human languages.
C++ Language Features
So far we’ve learned that C++, like all other programming languages except machine language, derives its
power through abstraction, and at least part of its speed from the fact that it is a compiled language. Now
let’s talk about how C++ compares to other languages, and what makes it a natural choice for game
programming.

C++ is sometimes referred to as a mid-level language a reference to its level of abstraction. C++ is more
abstract and therefore higher level than assembly language, and yet less abstract and lower level than a
scripting language such as JavaScript. This mid-level status is part of the reason that C++ makes a good
game programming language. C++ is low-level enough to allow very detailed instruction, and yet high-
level enough to allow for very complex concepts to be expressed and organized. Both are important for
game programming, which must address the computer hardware at a very low-level, and yet express and
manage high-level concepts such as the imaginary universe in which each game takes place.

C++ gets much of its low-level ability from its predecessor C, which allows data to be manipulated with
almost as much control as that provided by assembly language. Combined with higher-level data handling
functionality, this means that data can be manipulated either in large, complex data structures, or down to
the most fundamental level: the bit. Likewise, both C and C++ are procedural languages, meaning that
they both require that code be grouped into functions a function being a set of one or more instructions
that the computer is to execute. By providing support for the definition of functions and a variety of data
types, C and C++ provide the basic building blocks upon which any program can be written.

In this respect languages such as C and C++ are not unlike machine language except that names can be
given to both functions and data. But what if, instead of using a name to represent data, we wanted to use
a memory address to indicate where the data resides, as machine language does? This would allow us to
control not only the value of the data, but it’s location in memory as well. C and C++ support this ability
with pointers. A pointer is special data type that contains a memory address. It points to data by
indicating its address.

Pointers have a bad reputation. They are often mentioned as the primary reason why C and C++ are
difficult languages to learn. But pointers are very popular with those who have grasped the concept. The
truth is that pointers can be overused. Using pointers just for the heck of it tends to obfuscate code, and is
a common practice for insecure programmers. There are situations, however, where pointers are
invaluable. We’ll use pointers whenever it is appropriate throughout this course, starting in Lesson 2.

While C++ provides the features provided by C (functions and data types), the same is not true in reverse.
The C language is—for the most part—a subset of C++. C++ extends C by adding high-level features that
make it much more powerful than C. The primarily addition takes the form of classes. which are

www.gameinstitute.com Introduction to C and C++ : Week 1: Page 7 of 42
essentially the marriage of functions and data. (The name originally considered for C++ was C with
classes.) In C++, an object is a single instance of a class.

In C and C++, functions use data, and data can be manipulated by functions, but classes allow functions
and data to be defined as part of a single object. This is a simple concept that has powerful connotations,
because it allows programs to be modeled more closely on reality. By creating objects that contain both a
state (the data), and a means for modifying that state (the functions), C++ allows real world entities to be
modeled much more accurately and naturally. The object-oriented features of C++ make it an ideal
language for designing complex systems.

Combining functions and data to form objects is a powerful addition on its own, but is multiplied by the
fact that objects can be extended to create new, more powerful objects, without modifying the original
objects. This is called inheritance or polymorphism. Inheritance allows a new class of objects to be
created by defining only the ways in which the new type of object differs from the original type of object.

This course introduces C++ starting with the low-level features, and moving to the high-level features. In
this lesson and continuing in lesson 2 we’ll cover the fundamental features that C++ inherits from C. In
lesson 3 we’ll delve into C++ specific support for objects. In the remainder of the course we’ll build on
this foundation by exploring game-specific uses for these language features.

Before we get to the C++ language itself, we need to talk about the tools and processes that must be used
in order to convert C++ source code into an executable form. Programming, like any other craft, such as
carpentry, painting, or mechanics, requires that you become familiar with the tools of the trade before you
can fully concentrate on the craft itself. Knowing the C++ language is useless if you can’t usher your
source code into a usable form, just as knowing how to paint is useless if you don’t know how to acquire
and mix the required pigments.

Once we have an understanding of the tools with which we’ll be working, we will introduce the
fundamental C++ language topics upon which the remainder of the course—and the rest of your C++
programming career relies.
Development tools
Programmers generally come out of two camps: Windows and Unix. Programmers familiar with
Windows programming often start with Visual Basic, which provides an Integrated Development
Environment (IDE). An IDE is an application that allows the programmer to create and manage projects,
edit code, and compile source code into a form that is machine-readable. IDEs typically provide
debugging support as well, which allows the workings of a program to be scrutinized by stepping through
the code, line by line, as it is executed. IDEs often provide “Code Wizards” capable of generating small
projects or injecting code into existing projects in order to add new features. When you use an IDE, you
usually don’t see the contents of all of the code or the project files that make up each project. This has the
advantage of allowing you to concentrate on the application specific portions of the code and ignore a
significant portion of boilerplate code and configuration data.

Unix programmers, on the other hand, usually learn to program using command-line tools. In this case,
each of the tools required for programming is executed separately. There is no common graphical user
interface that unifies the programming tools. Code is compiled with one tool, linked with another tool,
and debugged with yet another tool (we’ll talk about each of these steps in more detail shortly.) In a
command-line environment, the management of code modules and projects is done by hand. Command-
line programming requires a higher level of familiarity with each project component than is required
when programming with an IDE.

www.gameinstitute.com Introduction to C and C++ : Week 1: Page 8 of 42

Windows C++ programming offers both options. Visual C++, for example, provides an IDE from which
C++ applications can be developed and tested. For Visual Basic programmers, switching over to the
Visual C++ IDE is fairly painless, as the interface and concepts are similar. But C++ has long-standing
ties with Unix, and as such still provides command-line tools. The Visual C++ IDE, in fact, merely
invokes these command-line tools behind the scenes. This means that programmers can opt to use these
command-line tools directly, and forfeit the use of the IDE. But if you’re new to programming, your best
bet is to start with an IDE.

Despite the fact that Visual C++ currently dominates the C++ market, it is important not to forget that it is
not the only option. Borland, for example (a company that dominated the C++ development tool market
for years before Microsoft, and is in large part responsible for the popularity of C++ on the PC platform)
offers a C++ development system called C++ Builder. Although it is not nearly as popular as Visual C++,
it is a perfectly good C++ development tool. These are just two of the development tools available for
Windows, and other platforms, such as Macintosh and Unix have C++ development tools of their own.

Because the emphasis of this C++ course is game development, and because the vast majority of games
and game-related tools are Windows based, we’ll concentrate on the Windows platform. This won’t be
obvious at first, as the samples that we start with don’t use any Windows-specific features, but later, in
order to introduce graphics, we’ll be using Microsoft’s DirectX toolkit, which is Window’s specific.

The development tools that we’ll focus on are Microsoft Visual C++ and Borland C++, each for different
reasons. We’ll target Visual C++ because it is by far the most prevalent C++ tool, both for game
development and in general. And, whatever your personal feelings about Microsoft, Visual C++ is a very
good tool. We include Borland in the mix both so that we don’t forget that Visual C++ isn’t the only C++
development tool, and because it is free.

In an attempt to attract customers, Borland has made the command-line version of their C++ tools freely
available. There’s no IDE, but a fully functional version of a very up-to-date tool is yours at not cost.
(There are free development tools available for Unix, so Unix users will be less surprised at this, but
Windows users are less accustomed to free development tools.) So, if you lack the funds to buy Visual
C++, or are not inclined to do so for personal reasons, there is an option. Each of the samples in this
course, in addition to including Visual C++ project files, includes support for the Borland compiler as
well. The command-line Borland C++ tools are available at this URL:

http://www.borland.com/bcppbuilder/freecompiler/

There is one additional reason why Borland is supported in this course. The Borland tools are ANSI
compliant. ANSI (American National Standards Institute) is an organization through which proposed C++
language features are ratified and thereby ushered into the official version of the language. Visual C++
includes many features that are of Microsoft’s own design and are not ANSI compliant. By checking your
work even if just occasionally with the Borland compiler, you can be sure that you aren’t inadvertently
using Microsoft-specific C++ features. This is a non-issue if you’re positive that your code need only
support Windows, but if you think you might want to use your code on Linux, for example, it is important
to keep an ANSI compliant compiler around.
C++ Mechanics
The code required for any C++ program is stored in a standard text file, usually with a .cpp extension.
The filename main.cpp, for example, might be used to store the primary source code for a project.

www.gameinstitute.com Introduction to C and C++ : Week 1: Page 9 of 42
Because cpp files are text files, they can be edited with virtually any text editor, such as Windows
Notepad.

In practice it is best to use an editor that is intended for C++. The Visual C++ editor, for example,
highlights language keywords and comments using different colors, making the code easier to read (in
theory, at least). Starting with Visual C++ 6, the IDE editor also makes suggestions while you type. While
this feature is of questionable value in a word processor, it is genuinely useful for writing source code, as
it can reduce time spent looking up function names and arguments.

The cpp file is human readable, but meaningless to Windows or any other operating system until it is
compiled. Compiling cpp files is performed with a C++ compiler, but the compiler is actually just one of
the tools required to convert source code into an executable form. C++ requires three steps in order to
convert source code into an executable form:

• Preprocessing
• Compilation
• Linking

The first two steps, preprocessing and compiling, are typically performed by a single tool, and therefore
appear to be the same step. Nevertheless, preprocessing is a separate and distinct step. The preprocessor
responds to different C++ language constructs than the compiler, and the compiler does not recognize
these constructs, so compilation cannot occur until the source code has been preprocessed.
The preprocessor
Preprocessing serves several purposes, one of which is to strip any comments out of the code. Because
code comments are removed by the time the compiler is invoked, the compiler is free to treat everything
encountered as code. In addition to comment removal, the preprocessor performs these two tasks:

• Macro expansion
• Header file inclusion

C++ macros work on a simple search and replace basis. Macros are used to define text that, when found
by the preprocessor, is replaced with other text. This is a simple and powerful tool. Macros can be used to
substitute complex instructions or even sets of instructions with simple names. Macros can also be used to
give frequently used values or strings simple and logical names. This allows multiple uses of a value to be
changed just by changing the macro definition. Macros can even be used to redefine standard C++ data
types.

The simple search and replace nature of macros is also what makes them dangerous. Unlike the compiler,
the preprocessor has a very limited and simplistic understanding of C++. This makes it is easy to write
macros that use conflicting data types, or work in one case but fail in others. The preprocessor performs
no type or syntax checking on macros, so the task of reporting problems falls to the compiler. And, while
the compiler will detect and report these problems, it has trouble reporting these errors efficiently because
the compiler is using the expanded version of the macro. When macros are used, the code you see in your
editor is different from the code that the compiler is given. Any errors that the compiler reports are
therefore reported in terms of the expanded macro, and do not reflect the name of the macro.

There’s another reason to be wary of macros. Consider, for example, that your program requires a lengthy
and frequently used operation. Rather than write code for the entire operation each time it is needed, you
can write a macro to perform the operation. This has the desired effect of centralizing the code required

www.gameinstitute.com Introduction to C and C++ : Week 1: Page 10 of 42
for the operation and simplifying the remaining code, but is has a possibly unwanted side effect. The
preprocessor, each time the macro is used, expands the macro. If the macro is used more than once,
multiple segments of identical code is expanded into your source code. To the compiler, it’s as though
you typed in the entire contents of the macro for each usage. This can be a waste of memory, and can
even have detrimental effects on performance.

With C (as opposed to C++) there are several cases where using macros is required, but C++ provides
safer alternatives for most of these cases. It is therefore usually best to avoid macros. Macros do have
their place, but it is a good idea to consider other options before using them.

Header file expansion is another task that is performed by the preprocessor. Header files, which typically
have a .h extension, are used to define data structures, macros, and special functions that are common to
multiple cpp files. Header files are never provided directly to the compiler. Instead they are inserted into
cpp files, which in turn are passed to the compiler. The preprocessor, whenever it encounters a header file
insertion command in a cpp file, inserts the contents of the header file into the cpp file. This is, in fact,
another form of a macro substitution, except that in this case the contents of an entire file are being
inserted into the code. The preprocessor doesn’t read header files except to remove comments and expand
macros. In all other respects the header file is simply pasted into the cpp file.

This means that the contents of a header file, once it has been inserted into a cpp file, are treated exactly
like the content of a cpp file. The compiler doesn’t know or care that the code it is compiling came
from a header file or a cpp file. Anything that can be put in a cpp file can be put into an h file, and vise
versa. Despite this fact, there are rules that should be followed about what gets added to header files.
We’ll talk about this distinction in Lesson 4.
The Compiler
The heart of any C++ development system is the compiler. This is the tool that reads C++ source code, in
the form of cpp files, interprets the data structures and code, and converts then into a binary form more
suitable for executables. The compiler does not, however, generate the executable output required to run
the resulting program. This is the task of the linker, which we’ll talk about soon.

Unlike the preprocessor, which understands just a few items in a cpp file, the compiler must understand
every character in the source code. If the compiler encounters anything that it does not immediately
understand, it generates at least one error message, and no output file will be generated.

To say that the compiler protests each time it encounters anything that it does not immediately understand
is not an exaggeration. In C++, with the exception of the standard data types, every construct that your
code uses must first be declared or defined. If a variable appears in the code that has not been formally
introduced, compilation will fail. If a function is called before being either defined or declared in advance,
compilation fails. (We will talk about the difference between definition and declaration soon.) Unlike
Visual Basic, which by default allows variables to be used without having been given a type in advance,
C++ is extremely type sensitive. No ambiguity about the nature of a variable or function is allowed.

If the compiler is able to interpret the contents of a cpp file without any errors, an output file is produced.
The output takes the form of an obj, or object file. (The term object, in this case, doesn’t have the same
meaning as that used in object oriented programming.) The obj file contains the compiled code in a form
that is very close to that of an executable, but lacks fundamental mechanisms and formatting required for
execution.


www.gameinstitute.com Introduction to C and C++ : Week 1: Page 11 of 42
Also, the obj file often represents only a portion of the code required for a complete application. Each
cpp file that is passed to the compiler results in one obj file. But a robust C++ program might have
dozens, or even hundreds of cpp files. The resulting obj files must be combined and reformatted in order
for an executable to be produced.
The Linker
Using the output from the C++ compiler, the linker performs the final tasks required to assemble an
executable. The linker, given one or more obj files, attempts to generate a single executable. If any
problems are encountered, the linker generates error messages. These messages are similar to the error
messages produced by the compiler, but linker errors tend to be less common than compiler errors. There
are also fewer possible linker errors.

Unlike the compiler, which generates just one primary type of output file (the obj file), the linker can
produce executables (or .exe files), library files (.lib files), or Dynamic Link Library files (.dll files).
Unlike exe files, which can be executed directly, lib files are used to store collections, or libraries of
compiled code. Typically lib files are used to store frequently-used functionality that can be used in more
than one final executable. For example, if you were running a game development studio, you might use
library files to store code that is shared between game projects. In this case the lib file would be necessary
for the compilation of each game. Once each game is compiled, the code contained within the lib files is
included in the executable, so the lib file is not required at runtime.

Dynamic Link Libraries are similar to lib files in that they contain compiled code, but are closer in
relation to executables because they are used at run-time. In the game studio scenario, common code
might alternatively be stored in a dll file, but the dll would not be required for compilation. Instead, each
game would require the presence of the dll only during execution. Only a header file and a type library
describing the dll features are required for compilation.

For our purposes, we’ll focus primarily on generating executable files. Especially in these early lessons,
our programs are too small to warrant the use of lib or dll files. Later, however, when we introduce
graphics and user input code into our programs, we’ll use compiled code libraries.
Compilation Process
To summarize the C++ compilation process, our primary concern is source code contained in cpp and h
files. To convert this raw source code into an executable form, a compiler, using either an external or
internal preprocessor, removes comments, expands macros, and inserts any header files that are used by
each cpp file. The result is one obj file per cpp file. The final step involves the linker, which converts obj
files into an exe, dll, or lib file. This process is illustrated below.


www.gameinstitute.com Introduction to C and C++ : Week 1: Page 12 of 42


Knowing what is involved in assembling C++ programs is important, but, regardless of whether you’re
using an IDE or a command-line tool, it’s not necessary to perform each step separately. The IDE, or a
command-line make utility will decide if and when each step is necessary, and perform it when necessary.

This brings up an important point. Most of the time it is not necessary or desirable to perform the entire
compilation process. If a game has dozens of cpp files, for example, and you make a change to one of
them, it’s only necessary to compile the modified module. The linker can then use the newly compiled
obj file module along with the existing obj files to generate a new executable. This saves the time of
compiling the vast majority of code. For the small programs that we’ll start with, this is a non-issue, but
as a project grows, it becomes more important. It is not uncommon for a full-scale game to take 30
minutes or even an hour for a full compile, even on a fast machine.

The C++ compilation process illustrates that many of the file types involved are disposable. Since
intermediate files, such as obj files, and final files such as exe and dll files are either the direct or indirect
result of the source code files, they can always be recreated. Therefore, for making backups of your
source code, or emailing a project to a friend or teammate, there’s little point in including these files. This
is good to know, since obj files, and some other compiler specific files, such as the Visual C++ pch file
(precompiled header file) tend to be quite large.
Project files
Writing C++ programs primarily involves writing and editing source code files (cpp and h files). But
other types of files are necessary in order to keep track of which source code files belong in a project, and
what dependencies exist between these files. These files are called project files.


www.gameinstitute.com Introduction to C and C++ : Week 1: Page 13 of 42
Visual C++ 5 and 6 use the dsp and dsw extensions to denote project files. (Visual Studio 7, otherwise
known as “Visual Studio.NET” no longer uses the dsp and dsw file extension for project files.)
Command-line compilers use makefiles, which sometimes have a mak extension, but are often named
simply “makefile”.

Although these files are not considered to be source code, they have much in common with the cpp and h
files that contain the source code. They are text files, they are necessary (or at least very useful) in order
for compilation, and recovering them if they are lost or deleted is time consuming. As a result, these
project files should be treated just like source code files. They should be included in backups, modified
with care, and should be deleted only if you’re positive that they are no longer needed.

This brings us to the subject of the samples and exercises that we’ll study in this course. For each sample,
you’ll be given source code in the form of cpp and h files, and project files, both in the Visual C++ format
and in the Borland command-line makefile format. If you are using Visual C++, loading the project is just
a matter of double clicking the dsw file.

Borland users will be working from the command prompt. Compiling the provided projects means
changing into the directory where you’ve saved the sample files, and launching the make.exe utility
provided with the compiler, which will in turn launch the required tools—in the correct order to compile,
and link the project.
Release and Debug Builds
By default most C++ projects are configured to produce two different versions of the executable: release
and debug. On the surface both look the same, but ultimately, the release build is the version that will
serve as a final executable version. The release build is smaller in size, and provides faster performance
because, in preparing this version, the compiler and linker were instructed to include only the essential
information, and to optimize for speed.

The debug build is a larger and slower version because no optimization is performed, and the debug build
includes information that is not required for normal execution. For example, the names of your functions
and data elements are all embedded into a debug build. These names, although vital for reading source
code, are normally disposed of by the compiler. (Remember, the compiler converts C++ source code to
machine language, and machine language doesn’t use text-based names). Despite their speed
disadvantage, debug builds are useful during development because they can be used with debugging tools.

Debugging tools, or debuggers, allow executables to be run interactively in a way that allows you to see
the effect that each line of code is having, allowing problems (bugs) to be located. The debugger displays
your code, and allows you execute it one line at a time, or up to any other line, and allows you to inspect
the current value of each data element along the way. In order to display source code and run executable
code in a synchronized fashion, the debugger requires a debug build.

The Visual C++ IDE provides an integrated debugger, and Borland provides a free version of their
debugger, so you can test debug builds regardless of which compiler you’re using. The samples provided
with this course include projects files that generate both debug and release builds.
Windows applications types
Before we get to our first program, we need to talk about the types of programs that we will be writing—
at least at first. The typical windows program, the ones we’re most used to seeing and using in Windows,
are windowed applications. C++ can be used to create windowed applications, but these programs are

www.gameinstitute.com Introduction to C and C++ : Week 1: Page 14 of 42
considerably more complex than the alternative. For this reason we’ll postpone learning about windowed
applications for now.

The alternative is called a console application. Console applications are text-based programs, and are
typically used for fairly utilitarian purposes. Console applications don’t support any of the user interface
components used in windowed applications such as buttons, checkboxes, or even popup menus. Despite
their Spartan appearance, console applications offer a key advantage over windowed applications:
simplicity. A small console application can be written in as little as 5 lines of code, whereas a simple
windowed application requires closer to 50 lines. Except for the lack of graphical support, console
applications enjoy every benefit of Windows programming.
Hello World
There is a programming tradition that the first program that a student is given is the “Hello World”
program. In observing this tradition, let’s start with a simple program that, when executed, displays the
text “Hello World!” within a console window. Here’s what the HelloWorld program looks like when
executed:



Admittedly, this is a humble start, but we’ll be writing more complex programs soon enough. The
HelloWorld program is implemented with a single cpp file, called HelloWorld.cpp. The contents of this
file appears here:

// The HelloWorld sample
#include <ostream.h>

int main()
{
cout << "Hello World!" << endl;
return 0;
}

The HelloWorld sample starts with a comment. Comments are ignored by the compiler, so they have no
effect on the final program. They are supported by the language so that programmers can leave notes in
the code.

The next line has an include directive. This is a preprocessor command that indicates to the preprocessor
that we intend to use at least one function or data type provided in a header file—in this case the
ostream.h file. The ostream.h header file is a standard header file, meaning that it is included with the
compiler. As such we don’t need to provide this file, nor concern ourselves with its content. We include
this file so that we can use the cout object, which we’ll talk about soon. Preprocessor directives are

Không có nhận xét nào:

Đăng nhận xét