Coder Profile - Show off your skills, get a coder profile.
 
 
 
Your First C++ Program
Programming
DoxCoding.com

Ok the best way to start is to tell you what we will do ;).

Ok. First we will be using:
-------------------------------------
Dev-CPP. (Type this in google to download it).
A Brain. (Vital)
-------------------------------------

Ok so i think we should really get started.

So lets start with a simple hello world application.

Ok to start this we can simply open Dev-CPP, File > New > Source Code. We can type all our code in there. Projects will come later if i do something thats neeeded. By all means if you want to use a new project you may.

So. the hello world.cpp

#include <iostream>

using namespace std;

int main()
{
cout << "Hello, World! \n";

system("PAUSE");
return 0;
}


Ok, so i guess you havent a clue on what any of this means do you?
This is what i am here for. To explain your first C++ program.

Lets start off with the first line of code.

#include <iostream> .
Lines beginning with a sign (#) are directives for the preprocessor. They are not used within the main code but are only used to firect to the processor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program.

using namespace std;
This is used to declare all the standard Output and Input such as 'cout' and 'cin'. without this we would have to keep typing in std:: or something like that. I am not too sure as i never used it. I always declared them at the start if i knew i was going to use them.
This line of code is always needed if you are going to use the standard library 'cout' , 'cin'.

int main()
This declares what part this is. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. As it seems and looks. 'main', the main part of the program goes inside here.

The two { and }.
These go after a function to kind of group the code underneath it together.

cout << "Hello World";
This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program.

'cout' is just basicly what you type to show some kind of writing on your command / application. As in this example [i]cout << "Hello, World";[i]
prints out Hello, World.

system("PAUSE"); and return 0;
This waits for another user input to show that the user is ready to close the application. It prints [i]Press any key to continue[i] the application will then close otherwise.

I hope this has helped some of you newbs out there.

Next time i have some spare time i will write a small tutorial on how to add in a variable and user input, then print out that user input.

Stay TUNED!

-[O]


Posted By otoom
Please login to rate coding articles.

Click here to register a free account with us.
Comments
Please login to post comments.
Page 1 of 1
More Articles By This Author
Quick Threading Tutorial - C++
First look at C
[PHP] How to make a log file.
[VB] Hello World
HTML Cheat Sheet!
[C++] Comments
[C++] Functions
[C++]Taking In User Input,
Your First C++ Program
Recently Posted "Programming" Articles
[PHP] - Lets kill the complex IF
Java: Obtaining User Input - Part 1
Basic PortScanner in VB6.0
N-Queens-Series Part I (Only the fittest survive)
Currying in JavaScript: Fun for the Whole Family!
[PHP] Create A Unique Page Hits Counter
Actionscript Events
Actionscript API
Quick Threading Tutorial - C++
C++ And Me (A Love Story)
Recently Rated "Programming" Articles
[PHP] - Lets kill the complex IF
Java: Obtaining User Input - Part 1
[C++] Templates
Quick Threading Tutorial - C++
Intorduction to memoization.
N-Queens-Series Part I (Only the fittest survive)
[PHP] Create A Unique Page Hits Counter
Currying in JavaScript: Fun for the Whole Family!
Actionscript Events
First look at C
source codes Categories articles
Browse All
Business & E-Commerce (1)
Databases (1)
Design & Creativity (1)
Internet & Web Sites (1)
Life In General (2)
Networking (1)
Operating Systems (4)
Other (2)
Programming (51)
Security (10)
Software Development (5)
Standards (1)
Web Development (15)
search Search Inside
Programming
 
 
Latest News About Coder Profile
Coder Profile Poll
What would you rate the design of Coder Profile?

9 to 10
7 to 8
5 to 6
3 to 4
1 to 2


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
5 Days Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2008, Scott Thompson, All Rights Reserved