C++ Programming Tutorial

[Note: make sure your file extensions are turned on before you continue.]

[Also note: this tutorial will work with almost every version of Microsoft Windows.  Some of the step-by-step instructions that I give may be slightly different on your system, so you may have to poke around a little to get things working.  If all else fails, ask me for help.]

Why am I here?

The purpose of this section is for me to share my knowledge of the C++ programming language.  It's a tutorial of sorts, and for anyone who's interested in learning to program, this is the perfect place to start.  Programming is fun and easy, despite the popular notion that you have to be somekinda genius to do it.

There are hundreds (maybe thousands) of different programming languages in existence; the one I will teach here is called C++.  It is the successor to the C programming language, and retains many of C's chracteristics.  C++ is widely regarded as "the best" or "the most powerful" or "the most adaptable" programming language.  Of course, everyone has different opinions, and many people prefer other languages to C++.  But today C++ is the most widely-used programming language (Microsoft Windows and a large percentage of Windows programs are written mainly in C++).

You don't need any previous programming experience to use my tutorial.  I'll assume very little computer experience as well -- I'll explain things as though you have no understanding of them to begin with, simply because this will allow me to accommodate the largest number of people with one single tutorial.  (If you're an "advanced" user and it seems as though I'm dragging my feet at times, please bear with me; we were all beginners at one point.)

I will not teach you everything there is to know about C++ (not even close), primarily because I don't know everything (not even close), and also because I don't have the time or space for that.  My goal here is to get you the software you need to make programs on your computer, show you how to set it up, and explain the basics of the C++ programming language so you can get started.  Then I'll point you towards some big tutorials that will allow you to start on the more advanced stuff in C++.

Who can code?

Anyone with a computer can write programs.  That is, an IBM-compatible PC (if you have a Macintosh, you must follow these special instructions: 1) unplug your toy. 2) go buy a computer. 3) come back here once you've done those things, we'll wait.)  To use the programming software that I'll give you, you need at least a 386 (if you're viewing this page on anything that old, congratulations) with 16 MB of ram and you must be running DOS.  You'll need about 50 MB of free hard drive space [to check, double-click on My Computer, then right-click on your C: drive and choose Properties.  Note that 1 GB (gigabyte) = 1000 MB (megabytes)].  In this tutorial, I'll assume that you're running Windows 95 or 98.  If you're not sure what all of this means, I'll say that if your computer is newer than 5 years old, you're probably ok.  But if you're unsure, please write me and ask, I'll be glad to help you.

What does this all mean?

Programming simply means writing programs (also known as applications).  So what are programs?  A program is a file on your computer that has a .exe or a .com extension (see my Help section for more about file extensions).  A program is executeable, which means that is does something when you run it.  For example, consider the "Paint" icon on the Start Menu (it's under Programs, then Accessories).  That icon is actually a shortcut (as all Start Menu icons are), and it points to the file mspaint.exe, which is stored on your hard drive at this location:

            c:\Program Files\Accessories\mspaint.exe

[I will now digress a bit into an explanation of how Windows handles files, and of how to use a DOS Prompt, because you need these skills to be able to write and use programs.]  It would be a nuisance if every time you wanted to use the Paint program, you had to double-click on My Computer, then the C: drive (your hard drive), then the Program Files folder, then the Accessories folder, and finally the file mspaint.exe.  So Microsoft came up with the idea for the Start Menu, which is a collection of shortcuts to executeable files (aka, programs) on your computer.  To better understand this idea, right-click on the Start Menu and choose Open.  Now double-click on the Programs folder, and find a file (not a folder) and right-click on it.  Now choose Properties.  Look in the Target box, and you'll see the file that the shortcut points to.  This means that whenever you click on the shortcut, it has the same effect as if you had gone through My Computer and found that program and double-clicked on it.

There's another way to access the file mspaint.exe -- the command prompt.  You can get there by clicking Start, Programs, then MS-DOS Prompt, or maybe Start, Programs, Accessories, Command Prompt.  You should get a window like this:

(Note: if your DOS prompt comes up full-screen, press ALT + enter to switch it to a window.)

According to that window, you're currently at the C:\Windows directory (aka folder), so you can type the name of any program that is stored in that directory and it will be the same as if you had double-clicked on My Computer, then your C: drive, then the Windows folder, and then the program.  For example, type "notepad" at the command prompt.  This should open the Windows notepad.  You can also access Notepad via the shortcut on the Start Menu, which is under Programs in Accessories.  Note that the shortcut is in the Accessories section of the Start Menu, but the program itself doesn't have to be in the C:\Program Files\Accessories folder.  A shortcut and the program it points to are completely independent of eachother.

Anyway... now you're at the command prompt.  It looks like C:\> or something similar.  Here are some commands that you need to know:

To do this...Type this...
To change to a different drive (D, for example)d: <enter>
To change to a subfolder (for example, to get from c:\ to c:\windows)cd windows <enter>
To change to the root of a drive (for example, to get from c:\windows to c:\)cd \ <enter>
To change to a subfolder whose name contains spaces, or is longer than 8 characters (for example, to get from c:\ to c:\program files)cd "program files" <enter>

[One final note before we get back to the programming stuff... I said before that a program is a file that does something when you double-click on it.  You may know from experience that if you double-click on, say, a picture file like a *.bmp, it will open the Paint program (or whatever your default picture editor is).  Doesn't that mean that that picture file is a program, because it opens up when you double-click it?  It would seem so, but the truth is that Windows is smart enough to know that that file is a picture, and so when you double-click on it, Windows runs the program mspaint.exe, which in turn opens the picture file for you.  The same is true of many file types, like a *.doc file -- when you double-click on one of these, Windows opens Microsoft Word, by running the program winword.exe.]

So, now that you know what a program is, and you know at least 3 ways to access programs (the Start Menu, through My Computer, and via a DOS Prompt), you would like to know how to make a program.  Making programs requires a special piece of software called a compiler.  (This is a program that you must obtain and install yourself -- Windows does not have a built-in compiler.  In the next section I'll get you set up with one of these.)  The process of writing a program goes like this.  First, you write out the program using a text editor like Windows Notepad.  This is called the source code, and is simply a text file written in the language of C++.  Once you've written the source code, you save the file with a *.cpp extension (for example, myfile.cpp).  Now you run the compiler, which makes an executeable file (which you might name myfile.exe) from your source code.  That's it, myfile.exe is your program.

Next: Setup