⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽

Introduction to C++

Computer Programming C++ / Getting Started

This chapter will introduce you to the basics of C++. If you are used to programming in Visual C#, much of this chapter will be review. Let's get started by creating a project.

If you do not have "Visual C++" templates available in the New Project window, you need to Modify your Visual Studio Installation.

Next, we need to create a file to write our code.

The Main Function

Every program needs an entry point. The windows applications that you wrote in C# had a file called Program.cs, that contained a "Main" function. Similarly, we need to create a starting point for our appliction.

To keep the console open when debugging, we will call a function named "getch." In order to use it however, we need to include a header file. We will go into the details of these files in the future. Once we have the window held open, we can print text to the console and have time to actually read it!

_getch() (short for "get character") waits for the user to enter a character. Usually, you would then do something with the character. In our case though, we don't care which key the user pressed. We just want to know that they pressed a key.

In upcoming sections of the chapter, we'll be writing to the console a lot. At this point, it might be good practice to write the previous section of code from scratch (or perhaps... To start press any key.). Once you can do that (without peeking), you're ready to move on!

Review Questions

The following are examples of questions similar to what you can expect to see on the next exam.

Hover over a question to show the answer.
  1. What is the "main" function for? It designates the entry point for the application. (where the instructions start)
  2. How many "main" functions can a program have? Only one. Having more or less will result in a compiler error.
  3. How do you make a single line comment in C++? // This is a single line comment.
  4. How do you make a multi-line comment in C++? /* This comment
    can span
    multiple lines. */
  5. What is #include <conio.h> used for? It allows us to use _getch().
⧼⧼  Previous Page
⧼  Table of Contents  ⧽
Next Page  ⧽⧽
© Ryan Appel