Main Page. VBA, ASP, Visual Basic 6.0, and VB.net. Visual C++, C#, C++, C. HTML and maybe javascript. Forum,Games and Jokes, other stuff. Submit a Tutorial Today!

C++ Tutorial: a guide to a new world.
Chapter 1. Welcome to C++

 

WHAT IS C++?

    C++ is a programming language designed mainly for lower level sorts of programming. Basically, C++ is used more for operating system and DOS commands. Lately, more interest has been taken in taking C++ into the gui, graphical user interface, world. C++ is more on the lower level of programming because a lot of the programming is done mainly by terminal input and not by gui like Visual Basic. Most versions of C++ also have an inline assembler to use assembly code. While this used to be important in the olden days of C, it is not being used as much. Not as many people are learning assembly as are learning C++.

WHEN DID C++ COME ABOUT?

    C++ originated in the early '90s as people saw that they needed more and more object oriented programming compilers. Originally, there was no C++, but only C. C is a functional programming language, meaning that there are no objects. The code goes from line one to the end. In C++, a big emphasis is placed on object oriented programming, basically breaking apart parts of programs into objects. I will cover this more in later parts of the tutorial.

WHAT WILL THE TUTORIAL COVER?

    This tutorial will hopefully cover a good portion of C++ on completion. There are planned sections on variables, input/output, structures, classes, and the list goes on and on. I hope that whomever uses this tutorial will have a good, working knowledge of C++. The tutorial will be put together to teach most of the basics and a few intermediate uses of C++ in the shortest amount of time. This means I won't bother to bore you with useless exercises that hardly anyone does for practice. You must practice on your own to keep up your skills. I can only teach you, you must be the one to take the initiative to write your own programs. That said, let us continue.

Section 1. Your first C++ program.

    In this section, we will use the basic output streams to output some text to the screen. I assume you already know how to run programs. If you don't, please learn how to before trying this section out, but if you insist, you should try pressing F5 or ALT+F9 on your compiler's IDE. If you have a console based compiler, the commands for compiling programs may differ based on compiler.

    In your compiler window enter the following code (you don't have to use italics on it :-).):

#include "iostream.h"

int main()

{

    return 0;

}

    Ok, the code above is a basic skeleton of a program in C++. The first line is a call for the compiler to include the stream file into the program. We will need this for later. The line with "int main ()" is a function declaration, you are telling the compiler to make the MAIN function and for it to be able to return a value. The braces are used to tell the compiler where the function begins and ends. Braces are used to tell where a lot of things in C++ begin and end, so don't be surprised to see them many times. The line with "return 0;" tells the function to return a value of 0, it's a standard thing to have to end a program in C++, but there are other ways to declare a main function. Oh yeah, note the semi-colon at the end of the "return 0;" line. This tells the compiler to end the statement. This is important because C++ is not bound by any sort of spacing. You can make a program that originally fits on 3000 lines fit on 1 line, and it will work perfectly. Weird, isn't it?

    Now let's take that skeleton and put something worth a little something in it. Before the return 0; statement and inside of the braces put this line in your code.

cout << "HELLO! WORLD!!!!!";

    This statement will, if you didn't already guess it, output "HELLO! WORLD!!!!!" to the screen. Run the program and see. If there is an error in the program, most compilers will tell you. Just make sure the code looks like the code above and try again. Be careful because C++ is case sensitive, you may have used the wrong case on one of the keywords in the program.

    That's it for this section. In the next section, I will cover some basic variable types and inputting from the console.


<--Previous Section Go Back to C Area. Next Section-->
 

Binary Central by Anman: "http://www15.brinkster.com/anman/"