CodeCrunch - http://www.codecrunch.com
Starting C++
http://www.codecrunch.com/articles/78/1/Starting-C--.html
By Daniel Phillips
Published on 06/28/2006
 
A very easy going guide to starting C++.

Easy Guide To C++

Starting C++ - 01

To follow this perfectly you need:-

- A C++ Compiler
- Knowledge in programming is useful


Right, lets look at some code:

#include <iostream>

using namespace std;

// this is a comment, this is not read by the compiler.
// namespaces will be explained later.

int main() {

cout << "Hello World!" << endl;

return 0;

}

 

Okay, now, lets look at it line by line:-

#include <iostream>

Without this line, none of the code would work, this includes the C++ code that makes the C++ program work.

using namespace std;

As the comments below state, namespaces will be done in later articles

int main() {

This line, starts our program.


Easy Guide to C++

cout << "Hello World!" << endl;

This line, is the bit that displays the text onto the console window, this displays Hello World! And then as of endl; it takes a new line.

return 0;

This enters the text: Press any key to continue...
Then closes the program.

}

Ends main() {, and closes our program.

C++ Dictonary so far:

#include - includes a file to the C++ document
using namespace std; - Later articles
int main() { - Starts a C++ program
cout << "" - outputs a string to the console window, stands for console output
<< endl; - Takes a new line, stands for end line.
return 0; - Ends our console program.

Thats it for this tutorial, check back for more soon!