The Organ Pipes
Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

 

 Tutorial: Hello World In C++

Go down 
AuthorMessage
pencillio
Administrator
Administrator



Posts : 8
Join date : 2008-06-14
Age : 30

Tutorial: Hello World In C++ Empty
PostSubject: Tutorial: Hello World In C++   Tutorial: Hello World In C++ EmptySat Jun 14, 2008 7:40 pm

The source code


Code:

// Hello World In C++

#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
    cout << "Hello world!";

    system("PAUSE");
    return 0;
}

What does it all mean?


Code:
// Hello World In C++
Is a comment - these are ignored by the compiler.

Code:
#include <iostream>
This tells the compiler to include the iostream library into the file. This is one of the most commonly used C++ libraries.

Code:
using namespace std;
Most programs in C++ require this line - everything in the standard C++ library is declared within what is called a namespace.

Code:
int main(int nNumberofArgs, char* pszArgs[])
This looks very confusing, but don't worry about it too much for now. All programs need this - the code starts executing when it sees the main() function.

Code:
cout << "Hello World!";
This statement writes "Hello World!" to the screen. The "cout <<" part is located inside the iostream, that's why we needed to include it.

Code:

system("PAUSE");
return 0;
These two lines make sure the user can see the results. If they weren't there, then the program would close as soon as you started it up!

Structure of the program


You will notice a few things about how the program is laid out. Here's why it's all done.

- Semicolons at the end of each statement. You need them otherwise the program won't know when the statement is finished!

- Curly brackets ( { } ). These simply mark the beginning and end of the main() function.

- Indentation. It's not entirely necessary, but it helps a lot with finding errors when you write more complex programs.

How do I compile it?


You can't run your program unless you have a compiler. Luckily, there are loads of compilers out there, including a lot of free ones.

I would recommend Dev-C++. You can download it here, and their official website is here

More tutorials coming soon!
Back to top Go down
http://www.theorganpipescom
 
Tutorial: Hello World In C++
Back to top 
Page 1 of 1
 Similar topics
-
» Tutorial: Hello World In GML
» Tutorial: Hello World In DarkBASIC
» Tutorial: First Webpage

Permissions in this forum:You cannot reply to topics in this forum
The Organ Pipes :: Programming :: C++-
Jump to: