HomeHome  FAQFAQ  SearchSearch  MemberlistMemberlist  UsergroupsUsergroups  RegisterRegister  Log inLog in  

Share | 
 

 Tutorial: Hello World In C++

View previous topic View next topic Go down 
AuthorMessage
pencillio
Administrator
Administrator


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

PostSubject: Tutorial: Hello World In C++   Sat 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
View user profile http://www.theorganpipescom
 
Tutorial: Hello World In C++
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Tutorial: Building a World Part 11 & 12 by Stw402
» Tutorial - How to create a world using Real-World Height data by Napalm_VFR
» Forge World 40 K
» Great Tank and Weathering tutorial
» Power Sword Tutorial (with more to follow)

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