Wiki:
Page name: C++ Class Basics [Logged in view] [RSS]
Version: 1
2005-12-16 18:11:01
Last author: Shadow-ofDeath
Owner: Shadow-ofDeath
# of watchers: 1
Fans: 0
D20: 13
Bookmark and Share

C++ Class Basics

Back to C++ Class


Here is an example of a working C++ program:

#include <iostream>
using namespace std;

void main()
{
cout << "Hello there, how are you today?"; //A little message
}


What do you notice about this program? The first thing that you should look for in any program is main(), as it is the first thing that every program goes to. It is the heart and soul of the program. Let's go through this program, piece by piece.

#include <iostream> - This little wonder includes a header file that allows you to use input and output in your program.

using namespace std; - This statement (semicolon means end of statement) tells which cout to use, like a program lastname. My advice: Don't think about it, just use it.

void main() - This is the main function. Void is the type of function, declaring it void means that there will be no output. If we declared it anything else, we would need a "return 0;" statement that exits it.

{...} - French braces hold in the body of the function.

cout - Means output, displays information on the screen.

<< - Separates different parts on the cout, such as constant strings and variable expressions.

// - Means a one line comment, is removed during compilation.

[#top]

Username (or number or email):

Password:

Show these comments on your site

Elftown - Wiki, forums, community and friendship.