Important alert: (current site time 7/15/2013 4:42:22 PM EDT)
 

article

C++ Intro...

Email
Submitted on: 9/20/2000 10:22:56 AM
By: Amin Patel1 
Level: Beginner
User Rating: By 87 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++, UNIX C++
Views: 118115
(About the author)
 
     This tutorial has been made to give an introduction to new c++ programmers. Unfortunately their are many great minds out there but they don't have access to free and quality c++ tutorials. So this is the first lesson.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
  1. You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
				

C++ Intro…                                       By: Amin Patel

Before you write your first program. Start with a prayer to God, that you “Succeed in learning C++”.

 

Now that all your hopes are high let us start. Please enter the following code exactly as shown, without any questions. (This is to inform you that the explanation will follow after the code.)

 

  1. #include <iostream.h>
  2.  int main()
  3. {
  4. cout<< “ What you do is what you get”;
  5. }

 

 

Although this may sound strange, once you compile this program you are a programmer.

<Warning: The numbered indentation is not to be included with the code while typing. It is only for your convenience>

 

Now let us read the first line. You read it as “Hash/Pound include eye-oh-stream-dot-h”

 

Iostream: Input Output stream. Don’t learn the definitions they automatically come to you.

 

 

You don’t pronounce the brackets while reading it loud, but is it a part of the code.

.h: Dot h files are known as header files. We place them in the beginning of the source code; it is like adding a DVD-Player to your deck. You don’t create .h files for now, nor would you add a DVD-Player to your deck each time you want to use it.

Iostream.h: Ok now you know what iostream and dot h stand for. If the terms input & output haven’t shed any light yet, keep reading. Iostream lets your program accept info/data/content or publish the same to the screen.

 

Wait we are still on the first line. Read the first line of source code again!

 

“Hash/Pound include eye-oh-stream-dot-h”

 

The Hash include is the standard form for telling the compiler that you want to include the Iostream.h file.

 

Now on line 2 we have int main().  Int is read as integer, read main() as main function. Without line 2 your program cannot work. On line 3 and 5 you have these {} braces.

 

Between the 2 braces all your code fits in. Make sure you enter line 4 exactly as it is. Pay attention to the punctuation.

Cout: See cout – It is the command with which you display text onto the screen

 

The << on line 4 is the redirection symbol produced on most keyboards by holding the shift key and pressing the comma key twice. The text in between the quotation marks, in the case “What you do, is what you get” is what shall be displayed onto the screen when you run the program.

 

Line 4 ends with a semi colon, don’t forget to type that, almost all c++ statements end with that. Now you may finally link, build and compile the code. Now you receive a message on a black terminal (Dos like): “What you do is what you get”

 

Congrats - You are now officially a programmer and that too c++.

 

I plan to write more tutorials when I can dedicate some time after school. If you like this code please give me a good message. I do need messages occasionally like “Thanks”, with all the pressure I face from school. If you have gained knowledge from this tutorial please make me happy.


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

9/20/2000 1:10:16 PMIan Ippolito

Amin,

Great tutorial--I think beginners will find it very useful.

Just to let you know, you can format your tutorial using HTML tags...this will let you add coloring/spacing, etc.

Keep up the good work!

Ian
PSCode Admin
(If this comment was disrespectful, please report it.)

 
9/20/2000 5:13:38 PMKamran

Wow, this tutorial really help me understand some things I didn't really get with the "Hello world" program.

(If this comment was disrespectful, please report it.)

 
9/21/2000 7:47:36 AMAmin Patel

Dear everyone, thanks for making me happy. Ian Ippolito I have now incoperated a new html layout and design. Since people made me happy, I even added colour coding.

(If this comment was disrespectful, please report it.)

 
10/4/2000 5:45:37 PMalaa

this code contains errors:
i think that any programmer in c++ should know that the function
int main() should return a value.
the good listing should be like this:
int main()
{
/*YOUR CODE*/
RETURN 0; //or any integer
}
OR
void main()
{
//YOUR CODE
}
you should learn to people what is true.
(If this comment was disrespectful, please report it.)

 
10/5/2000 7:30:53 AMAmin Patel

return 0; would be appropriate, had I taught data types. Thanks for noticing.
When you learn data types(int, float, void), it is a good time to explain.
(If this comment was disrespectful, please report it.)

 
10/8/2000 7:03:25 AMalaa

then, please do not use int , and use void.(it will not generate a warning)
(If this comment was disrespectful, please report it.)

 
10/8/2000 9:44:45 PMOliver .j. Malik

This tutorial is really informative for its size! It's MUCH more concise than the SAMS
(If this comment was disrespectful, please report it.)

 
10/16/2000 8:23:47 PMKory

you forgot << endl;
(If this comment was disrespectful, please report it.)

 
10/17/2000 7:32:31 AM>Link

ok

I NOW know how to program in c++, thanks to this tutorial, and many other i found on the internet.

I probably cannot 'speak' here because i am an 'amuture': I compiled and wrote (other way 'round!) this here little program, and it works like my bike chain, after it's been oiled! THERE IS NOTHING WRONG WITH IT!

Although feel free to dissmantle and destroy my comment, as it is based on: 'it works, i don't care' atitude.
(If this comment was disrespectful, please report it.)

 
10/19/2000 5:38:18 AMCraiguess

This is so KooL man!
but only one problem...
When i tried to do the exact instructions in 1st box
where it says;
1.
2.
3.
etc.
i typed it exactly into my colpiler
and it didn't work..
it wouldn't compile because it came up
with one error;
The first line..


(If this comment was disrespectful, please report it.)

 
10/19/2000 8:10:21 AMAmin Patel

Craiguess,
Since problems due to different compilers and compatibility were occuring the 3rd tutorial starts with and addresssing of the problems, check it out at: http://www.planetsourcecode.com/xq/ASP/txtCodeId.805/lngWId.3/qx/vb/scripts/ShowCode.htm

(If this comment was disrespectful, please report it.)

 
10/19/2000 11:06:31 AMzoka

This progam is perfect. Also statemant
(If this comment was disrespectful, please report it.)

 
10/20/2000 6:47:49 PMarra

in place of <
(If this comment was disrespectful, please report it.)

 
10/20/2000 6:49:32 PMarra

in place of <when it is initiated, to signal to the complier that the program has run its course, ie.. return void or return 0.
(If this comment was disrespectful, please report it.)

 
10/22/2000 7:51:51 AMAmin Patel

Thanks arra but I wish to do that once data types have been explained, but since you have mentioned it, ppl before you close your program with the } brace plz. type:
return 0;
It is a good programming practice, it tells the compiler that you have succesfully terminated.
(If this comment was disrespectful, please report it.)

 
10/24/2000 11:07:56 AMCooLViruS

I like the way you explain everything...although there are some mistakes...but don't you think that it's too simple?I believe you should add some more (commands,functions) to the tutorial in the place of the pronouncing part. I don't think that anyone is really interested in that.
(If this comment was disrespectful, please report it.)

 
10/24/2000 11:20:59 AMCooLViruS

It's a "sweet" tutorial but shows almost nothing. It would make a lot of people happy if %d was explained and if you would put an exaple of it.The way you explain is good.(I believe that the pronouncing part is useless).It's better that no mistakes are found in tutorials.Especialy the ones for beginers.
(If this comment was disrespectful, please report it.)

 
10/25/2000 12:20:59 AMah

Thanks
(If this comment was disrespectful, please report it.)

 
10/25/2000 12:59:39 PMAmin Patel

Hey Virus, actually the pronouncing part only helps you communicate the code to your friends, I know many people who even pronounce it wrong. Anyway thanks for XPRESSING your self. Regarding 'mistakes' plz. refer tutorial 3, different compilers, different styles, different ppl. You know what I mean.
(If this comment was disrespectful, please report it.)

 
10/25/2000 4:49:16 PMXIX

Great JOB DUDE! C++ can be fun when u have a fun way of learning it.
(If this comment was disrespectful, please report it.)

 
10/31/2000 8:52:25 AMkarthik

hey,
u're tute is really good, I am new to this & I really would appericiate if u can keep this up.& can u tell me any websites or tutorials which is good for a beginner like me.(from the scratch) it would be greatful, thanxz.
keep up the good work, people like me depend on u.
(If this comment was disrespectful, please report it.)

 
12/10/2000 9:01:30 PMarra

in%2Bplace%2Bof%2B%253C%253Cendl%253B%2Byou%2Bcan%2Balso%2Butilize%2B%255Cn
(If this comment was disrespectful, please report it.)

 
12/19/2000 1:36:34 AMBiofreak

Good work ;o)
(If this comment was disrespectful, please report it.)

 
12/23/2000 1:44:35 AMConfined

what else do you know how to do in c++, Amin?
(If this comment was disrespectful, please report it.)

 
1/1/2001 7:52:12 AMMatt Savage

great tutorial for a first time user!
thanx alot d00d!
(If this comment was disrespectful, please report it.)

 
1/3/2001 2:29:28 AMHELLRAISER

I get an error when i compile it..

error spawning cl.exe

can you help me....
(If this comment was disrespectful, please report it.)

 
1/7/2001 3:10:02 PMmike

Thank you Amin,it is sometimes hard to find a person with a good heart who will take the time to share knowledge,Ihope your lifes endevours are pleasing and blessed...thanks
(If this comment was disrespectful, please report it.)

 
1/7/2001 3:14:37 PMmichael

Thanks Amin, for taking the time ans having a good enough heart to help others..thats a good quality in a person I hope you are blessed for your sharing of knowledge,,thanks
(If this comment was disrespectful, please report it.)

 
1/18/2001 6:44:21 AMAmin Patel

: The 2 links provided by me previously have changed, you can directly reach the two sites using -
Tutorial 2
___________
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?lngWId=3&txt CodeId=773

Tutorial
3
__________
http://www.planetsourcecode.com/xq/ASP/txtCodeId.805/lngWId.3/qx/vb/s cripts/ShowCode.htm


(If this comment was disrespectful, please report it.)

 
2/13/2001 7:52:34 PMkskinner

Very nice! I am new to C++, and did actually understand what you were trying to get across. Don't let the critics get to you, you are providing a good service to us all!!!! Thanks.
(If this comment was disrespectful, please report it.)

 
2/16/2001 10:57:12 PMStanley freifeld

Very informative! Good for a newbee to
be exposed to.
Thank you
(If this comment was disrespectful, please report it.)

 
2/28/2001 3:21:28 PMDave Dyer

Hey Amin, very nice work on the post, it was explained for beginners very nicely,and it's not too much to digest. It's stuff I already know, as I am fledgling programmer, but the way you write it makes it incredibly easy to understand. I look forward to reading your other posts, please keep them up! As for the
(If this comment was disrespectful, please report it.)

 
2/28/2001 3:22:11 PMDave Dyer

Hey Amin, very nice work on the post, it was explained for beginners very nicely,and it's not too much to digest. It's stuff I already know, as I am fledgling programmer, but the way you write it makes it incredibly easy to understand. I look forward to reading your other posts, please keep them up! As for the "errors" in the code, there are about 25 different ways to write this little tidbit of code, none of which are "right" so keep your opinions to yourself please, so as not to confuse the people who really need this code, the beginners, like me. Thanks again for the post.
(If this comment was disrespectful, please report it.)

 
4/19/2001 9:32:22 PMeagle

Well as long as you return 0 you don't get any warnings. Great beginning code man. I'm trying to get C down packed so it's easier for me to mess with Linux stuff.
(If this comment was disrespectful, please report it.)

 
4/23/2001 7:29:27 PMLord Nova Ice

Nothing Special here, but its good for begginers(just not me) in c/c++
i would like to see more examples with borlands C++ Builder for windows apps.
(If this comment was disrespectful, please report it.)

 
5/30/2001 7:19:57 AMxiaodong

good
(If this comment was disrespectful, please report it.)

 
5/31/2001 7:34:51 PMCybrgoon

Well, Amin ... a very nice and well done tutorial(spoken as a true beginner.) I have a request though: When you put code examples into your tutorials, could you comment the portions of the code that are
(If this comment was disrespectful, please report it.)

 
6/6/2001 9:39:06 PMSoheil Yasrebi

That was just great, because this was thefirst thing I ever read about the C programming and I learned someting from it. Anyway I had a quetion to ask that what country are u originally from??!
(If this comment was disrespectful, please report it.)

 
6/10/2001 6:34:47 PMNeil Ramsbottom

I am sure that I have seen this tutorial on www.codeproject.com, but with a different authors name on...
(If this comment was disrespectful, please report it.)

 
6/26/2001 6:50:50 PMPrytanis

The water has been tested and it is not as frigid as I thought it would be.
Thanks Amin, well done
(If this comment was disrespectful, please report it.)

 
6/27/2001 1:48:58 PMAmin Patel

To: Neil Ramsbottom
Tutorials (1-3) of mine exist on codeproject too.
(If this comment was disrespectful, please report it.)

 
7/10/2001 9:09:15 PMjoahnna

I am a true beginner. at least learning the basic is something! Thanks!
(If this comment was disrespectful, please report it.)

 
8/1/2001 9:02:20 PMDeryck H

Thanx dude, that helped a lot. Now I'll take your other 2 tutorials.
(If this comment was disrespectful, please report it.)

 
8/11/2001 10:40:32 PMAkuma no Houkon

It was a nice tutorial, but did not go in areas that I am in need of assistance in, I am trying to learn C++/VC++ and I have been programming for 8 years and have used every style of language avialable except for C++ style lanugages and asm. I try and learn this, even with your tutorial, and it just goes in one ear and out the other (probably because I have mastered all versions of VB, and Basic, HTML, ect. so the C++ style just inst sinking in, can someome PLEASE HELP.
LeadProgrammer@CrypticDesigns.com Thank you.
(If this comment was disrespectful, please report it.)

 
9/24/2001 10:18:21 AMn

n
(If this comment was disrespectful, please report it.)

 
10/12/2001 4:37:25 PMtraceywindsor@hotmail.com

This is an awesome start to tutorials, please keep it going. If you don't mind, I will be suggesting this tutorial to all of the CPSC100 students at my school who are learning C++ for the first time. This is an excellent example, with none of the tech-styled language. If I had read this when I first started programming, I'm sure that I would have had a much better understanding over the first few lectures. Thanks again! Tracey
(If this comment was disrespectful, please report it.)

 
11/4/2001 4:36:48 AMChris

Great! =) For Visual C++, line 2 should say
(If this comment was disrespectful, please report it.)

 
11/4/2001 4:38:48 AMChris

PSC messed up that last line. I meant to say for Visual C++, line 2 should say

void int()
(If this comment was disrespectful, please report it.)

 
11/7/2001 11:26:17 PMBrett Birkett

If this tutorial is for beginners, why does the first tutorial not show how to compile and link?? Compilation of source code is assumed knowledge i noticed. - Brett.
(If this comment was disrespectful, please report it.)

 
11/11/2001 3:01:26 PMimn0thing

dude, i dont know how you got so many good ratings. you can read the first 4 lines of any C++ introduction book and learn more than this tutorial. your explanations don't make much sense, and it only introduces a single, standard library function (cout). this is ridiculous.
(If this comment was disrespectful, please report it.)

 
12/2/2001 5:32:16 AMji

i haven't even tried to usethe code yet, or read the tut all the way, but i can tell that this guy did some good work for a beginner's tut. i'm sure most of the inspired c coders that go on the greener pastures will forget this code and perfect thier own ware. so as far as the previous post, i'd have to agree that 'urn0thing'.
(If this comment was disrespectful, please report it.)

 
12/10/2001 5:52:32 AMTelegeek

It really helps a N00b
(If this comment was disrespectful, please report it.)

 
12/17/2001 3:55:54 PMY-NOT

Thank you, I have been looking everywhere for information like this,it is GREAT!!!, there is one other thing no one has helped with, (remember) I am a beginner, ? Where do you start? MS-DOS, Notepad, redhat,....ect....?????
(If this comment was disrespectful, please report it.)

 
12/21/2001 8:58:22 PMBal Canete

Hi Amin, 'am very much confused of C/C++ until I've read your tutorial. Thanks a lot man, please publish some more.
(If this comment was disrespectful, please report it.)

 
1/16/2002 11:17:39 AMRamadan

Excellent job!
(If this comment was disrespectful, please report it.)

 
2/21/2002 4:46:59 AMKeolebogile Mokolopo

Your intro of C++ is very good,but i'm wondering if you can help me with the project i have to do.
my email is:2001017546@wwg3.uovs.ac.za
If you are willing please reply.
(If this comment was disrespectful, please report it.)

 
2/21/2002 4:48:52 AMKeolebogile Mokolopo

It's very good,i'm impressed

(If this comment was disrespectful, please report it.)

 
5/9/2002 6:10:26 AMuv

really helpful
(If this comment was disrespectful, please report it.)

 
7/8/2002 8:07:36 AMClif

Hey man! Just a quick one to say great job & thanks. The only experience I have had is in BASIC (remember that?) and your tutorial more than helped open a new door for me. It was very basic, but got the point across. Also, by reading other tutorials as well as comments from other programers, there is more than one way to skin a cat. The whole experience was very enlightening to say the least. Hope to see more tutorials from you in the future, and thanks again for sharing your knowlege on this one!
(If this comment was disrespectful, please report it.)

 
8/5/2002 5:40:15 PMjohn sheridan

i typed in those first couple of lines, tried to run them, and it said "102 errors found". i don't even know if thats possible cuz it doesn't even have 102 characters...wierd...
(If this comment was disrespectful, please report it.)

 
8/28/2002 6:49:24 AMSteven Adams

Very useful for beginners in programming, and it's free too. Informative for it's size, and once you've read this 2 times, you've already learnt the utter basics, and you aren't bogged down by all these jargon words. Good work!
(If this comment was disrespectful, please report it.)

 
9/16/2002 12:22:15 PM

Awesome work...! Keep it up..Need more from you!
(If this comment was disrespectful, please report it.)

 
9/30/2002 11:49:47 AM

USING YOUR INFO TO MAKE NOTE CARDS
(If this comment was disrespectful, please report it.)

 
10/14/2002 12:11:03 AM

Buddy its good for a beginner but u must do something for ppl who are stuck in b/w like me.....knowing the basics but still having no idea about the more complex things such as- making header files etc. .....
(If this comment was disrespectful, please report it.)

 
2/13/2003 12:00:23 PM

Having recently started learning C++ myself, I have to say this article is poorly written, does not explain things correctly, and gives people no serious start in C++ that 5 mins on google won't do. Sorry but even targeted at beginners this is poor.
(If this comment was disrespectful, please report it.)

 
2/18/2003 7:39:27 AM

i must know full details in meaning full manner about c++ and also i expect to be master in c++
(If this comment was disrespectful, please report it.)

 
4/23/2003 9:13:27 PM

Thanks for the very basic tutorial. I learned much from it!!! Thanks!!!
(If this comment was disrespectful, please report it.)

 
7/2/2003 4:00:18 PM

For those in search of tutorials of programming in C++ try about.com's free tutorials on the subject.
as for my opinion of this, "this is good how?", comes to mind
(If this comment was disrespectful, please report it.)

 
11/4/2003 1:21:10 PMvivek patel

if u vote for this code.......than u will really enjoy my code...logon to http://www.vivekpatel.cjb.net and enjoy the nice source-code all for beginners and advance users
(If this comment was disrespectful, please report it.)

 
11/27/2003 2:00:23 AM

Hey when ever i try to compile the thing in dev-c++ the dos window just flicks on and off real fast so i can see any thing. lol
(If this comment was disrespectful, please report it.)

 
11/27/2003 2:05:28 AM

Oh sweet tut. i actually understood it unlike the millions of others that are similar and i couldnt understand it.
(If this comment was disrespectful, please report it.)

 
1/1/2004 1:26:58 PM

i use dev c++ and the screen just flickers and then it exits do you no why? plz help
(If this comment was disrespectful, please report it.)

 
5/29/2004 6:58:12 PM

This is a good tutorial that helped me understand the beginning of C++, thx
(If this comment was disrespectful, please report it.)

 
6/13/2004 5:53:33 PM

Hello, I am having problems compiling the first program in this course. My compiler(Dev C++) keeps bringing an error on the first line:#include . What should I do about this error?
(If this comment was disrespectful, please report it.)

 
12/20/2004 3:41:08 PM

Since this tutorial is among the most popular, it should be updated. Some compilers issue warnings if you use #include . iostream.h is now deprecated. The new thing is:

#include //without the .h
using namespace std;


(If this comment was disrespectful, please report it.)

 
2/18/2005 8:46:43 PM

Good Info for beginners...Hey, are you the guy that wrote SRE/BRE back in the 80's ?

(If this comment was disrespectful, please report it.)

 
7/5/2005 10:41:36 PM

Thanks so much for this! I'm new to programming anything besides HTML. I've done the "Hello World" program successfully, but I wasn't quite sure how it worked. This tutorial really helped me understand what everything was for.
Thanks
(If this comment was disrespectful, please report it.)

 
1/24/2006 7:11:16 AMjeffrey

hi, im just starting out on c++ and i downloaded Dev-C++ 4.9.9.2, and using that bit of code from this page it told me to replace the "antiquicated header with , but as soon as i did the cout line comes up with a cross next it and in the compiler list it says there is a stray /127 and a stray /148 in the line as well as that it expects a ; before the word you and that cout is undeclared as it is the first time it is used in the function. now this is greatly confusing me and i was wondering if anyone could tell me what was happening that shouldnt be.

p.s. i just put the ; in front of you and it told me that you wes undeclared and to put ; infront of get which it then told me was undeclared when i did so.

jeffrey
confused
(If this comment was disrespectful, please report it.)

 
7/26/2008 6:09:16 PM

#include
int main()
{
cout<< “ What you do is what you get”;
}
(If this comment was disrespectful, please report it.)

 
7/26/2008 6:10:40 PM

I did exactly what you said to do, but I keep getting this error:
fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

I use Microsoft Visual C++ 2008.
(If this comment was disrespectful, please report it.)

 
8/20/2009 11:11:57 AMRiden

for a guy who doesnt know much about programming this tutorial really explained a lot. Great Work!!
(If this comment was disrespectful, please report it.)

 
8/25/2012 9:10:15 PMarpanraj

if u have one side school exam and one side c++ what will u choose
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.