Game Development Reference
In-Depth Information
The first two lines of this source code are comments. A double forward slash indicates that all text
following the // on the same line should be ignored by the compiler. Block comments are also
supported and are opened with /* and closed with */ . You will see several uses of both forms of
comment throughout this topic.
There are then several lines beginning with #include . This tells the compiler to include other files into
our program. We cover the difference between source and header files in Chapter 6.
The next line tells the compiler that we want to use the standard namespace. Namespaces are also
covered in Chapter 6.
The program then begins with the _tmain function. This is the first function called by the program
when writing Windows applications that target the console. Different operating systems have
different entry points and you'll see these throughout this topic as different examples are written to
target different operating systems and compilers. You should be able to easily alter the samples to
use the entry point for your system of choice.
The cout operator writes the text following the << operator to the console window. The cin operator
stops the program and waits for the user to enter text. We store the text entered into the name variable
and then use it to echo back the input the user entered.
The last line returns the value 0 from the function to let the operating system know that we finished
without error.
As you can see, this simple program asks for the user's name and then repeats that name back to
the user. Congratulations: You've written your first C++ program.
Summary
This chapter has given you a very brief introduction to the C++ programming language. We've
looked at the basic history of the language, the current main C++ compilers, its major paradigms,
and a simple C++ program.
The next chapters look at how we can create some simple games using the C features of C++,
beginning with a look at the fundamental built-in types and operators in C++.
The examples in Chapters 2 and 3 are simple programs that will help you to understand how C++ types
and operators behave. The examples beginning in Chapter 4 see us begin to create a text adventure
game that we will develop to completion throughout the remainder of the topic. Text adventure
games were very popular on early computers and they are an excellent way to learn C++ for game
development without requiring you to learn the intricacies of a platform-specific windowing system or
graphics application programming interface (API).
 
Search WWH ::




Custom Search