Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 24th, 2005, 5:11 AM   #1
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Hello World! - C++ Tutorial

This article will show you the very basics of C++ programming.

I'll assume that you have never programmed in or even looked at C++.

C++ (pronounced See Plus Plus) is a compiled programming language, useful for making desktop
applications, algorithms, games etc. You can write you C++ program in any text editor and use
a program called a compiler to create an executable of your program.

The best free compiler/IDE (Intergrated Development Environment) is Dev-C++, you can download it for
free at http://www.bloodshed.com. Install it using the install wizard, and then your are ready for your
first program.

Open Dev-C++, click File>New>Source File or press CTRL + N. From here you can type in your C++ program
and it will higlight your syntax and auto indent your code.

Now type the code from Program-1 into Dev-C++. I suggets you type it rather than copy and paste it, that
way you will remember it and learn it more than if you just copy and paste it.

Program-1:
//Hello World Program
#include <iostream>
using namespace std;

int main()
{
	cout<<"Hello World";
	cin.get();
	return 0;
}

Now, click File>Save and save it as: HelloWorld.cpp (the cpp extension stands for c++). Then click
Execute>Compile, it should compile without any errors, so you can just press Execute>Run and it will
run the program you just made. Also look inside the directory where you saved HelloWorld.cpp and you
will see a file called HelloWorld.exe you can run this by double clicking it. Congratulations! You have
compiled and ran your first C++ program.


Hopefully, by now you will be wondering how it works, I'm going to go through the code line-by-line
so that you will understand what each line does.

Code: //Hello World Program
Description: This is called a comment, if a line begins with // it will be a comment. A comment is ignored
by the compiler so you can type anything after the //. It is designed so that you can write human
readable comments in your code.


Code: #include <iostream>
Description: This includes the iostream header, iostream stands for input/output stream. If you include
this into your files it will allow you to take in input and send out output.

Code: using namespace std;
Description: This makes the std namespace global. It is hard to explain it when you have only just started,
but you should include this in your code. If you dont you will have put std:: in front of standard
functions, such as cout. cout<<"Hi"; would become std::cout<<"Hi";

Code: int main()
Description: This is the main function. Every C++ program must have a main function. And code between the
{ and } will be executed when the program is run.

Code: cout<<"Hello World";
Description: This code writes the text Hello World onto the screen, as you saw when you ran the program.

Code: cin.get();
Description: This code makes it so that you have to press a key before the program continues, without it the program
would just flash on the screen and then off again.

Code: return 0;
Description: This makes the program end successfully, if you use return 1; it means that there has been an error and
it has to exit unsuccessfully.



Ok I hope you have learnt something from this tutorial, it should help you when you go onto a complete tutorial about
the C++ language.

Recommended Links:
http://cprogramming.com
http://cplusplus.com
http://cplus.about.com
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Sep 24th, 2005, 9:52 AM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Nice tutorial, looks really thorough. Good job.

You even told us how to pronounce C++...
__________________

tempest is offline   Reply With Quote
Old Sep 24th, 2005, 10:15 AM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
LOL @ tempest. I always just say "See", then spit twice.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 24th, 2005, 10:28 AM   #4
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
@tempest
thanks

I've heard people say "See add add" and "See Positive" so i thought i'd say how to pronounce it so that people dont make that mistake
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Sep 24th, 2005, 11:52 AM   #5
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
When i was a n00b i called C# C-pound... i still do if there's a programmer around me who needs a good laugh.
__________________

tempest is offline   Reply With Quote
Old Sep 24th, 2005, 12:04 PM   #6
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Lol i thought it was C-Hash before i read any tutorials.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Sep 24th, 2005, 12:49 PM   #7
crazykid48x
Programmer
 
crazykid48x's Avatar
 
Join Date: Apr 2005
Posts: 96
Rep Power: 4 crazykid48x is on a distinguished road
I just found out that "cout" is pronounced "see out" a while ago from my for dummies book.
crazykid48x is offline   Reply With Quote
Old Sep 24th, 2005, 12:57 PM   #8
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
i still pronouce it "cowt", it just sounds better to me..
__________________

tempest is offline   Reply With Quote
Old Sep 24th, 2005, 1:34 PM   #9
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
i thought C++ was pronounced kuh-plus-plus.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Sep 24th, 2005, 2:37 PM   #10
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
So who pronounces "char" as in charred steak, rather than as in the first syllable of "character"? Blows my mind every time I hear it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:18 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC