C++ Part 1

CMPC :: Computing :: Programming :: C++

Go down

C++ Part 1

Post by Unchained on Sun Jan 24, 2010 9:17 am

Ok so heres my super simple C++ tutorial for beginners!

Part 1: "Hello World!"
Traditionally a programmers first program is called the "Hello World!" program. Simply put, it prints the above words (or anything else you want, I don't care) to the screen.

Here are the things you will need:
A compiler - http://www.microsoft.com/express/Downloads/#2008-Visual-CPP (Windows only, Allen can suggest something for a mac)
NOTHING ELSE! Well sort of, that above download is sort of an all in one, sometimes you need other things.

So yea just go and install that. Afterward you will need to setup a new project, for now I suggest you select the option "empty project" If all goes well you should be looking at a blank project.

So here's what I'm going to do: Compilers ignore everything after "//" (without quotes) so I'm going to use that to comment below.

Code:

#include <iostream> //required to input and output text

using namespace std; //a shortcut, see #1

int main() //Where your program begins, see #2
{
cout << "Hello World!"; //prints the words to the screen
cin.get(); //waits for you to press enter
return 0; // see #3
}

1. Without this you would need to type "std::cout" and "std::cin" every time. It isn't best practice but for now I'll be using it.
2. The "int" in this means it is waiting for a number to be returned before it ends. This can be substituted with different things such as "void" which ends the program after the last command. Also, everything in the brackets belongs to "main".
3. This gives the program the number it wants before it ends. 0 means it worked correctly, 1 or other numbers means it failed.

Homework:
1. Copy and paste my program, then select compile, then run.
2. Get it to say something else.
3. See what happens when you remove "cin.get();"

I'll be happy to answer any questions, it can be difficult for those just starting off.
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Admin on Mon Jan 25, 2010 1:55 am

I don't see why the hundreds of thousands of C++ tutorials on the internet could not be understood by Annie, but this could. You see where I'm going with this?

_________________
avatar
Admin
Pirate King

Posts : 559

Back to top Go down

Re: C++ Part 1

Post by Unchained on Mon Jan 25, 2010 1:57 am

Yea but its more like talking with this because they can ask questions and such.
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Admin on Mon Jan 25, 2010 1:59 am

dreamincode.net and cprogramming.com has forums..... JUST LIKE THIS ONE. except with a few thousand more users.

_________________
avatar
Admin
Pirate King

Posts : 559

Back to top Go down

Re: C++ Part 1

Post by Unchained on Mon Jan 25, 2010 2:02 am

Yea but it doesn't help that they are all Indian and the ones who aren't are dicks.
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Admin on Mon Jan 25, 2010 2:10 am

lol i hate the dickheads. they're the worst. fucking 30 stars under their avatar and they just redirect you to the tutorial.

_________________
avatar
Admin
Pirate King

Posts : 559

Back to top Go down

Re: C++ Part 1

Post by Batguano on Mon Jan 25, 2010 4:08 am

Ok, so Mel has my laptop (Windows) and I'm stuck on my mac and I'm totally lost with the XCode shit... yea..
avatar
Batguano
Ninja

Posts : 101

Back to top Go down

Re: C++ Part 1

Post by Admin on Mon Jan 25, 2010 4:20 am

this is just ONE reason why macs suck. but another_pd has experience with xcode. ask him about it.

_________________
avatar
Admin
Pirate King

Posts : 559

Back to top Go down

Re: C++ Part 1

Post by Unchained on Mon Jan 25, 2010 4:21 am

Yea sorry, I cant stand macs...
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Batguano on Mon Jan 25, 2010 5:00 am

I like my mac but like... I prefer my windows for programming stuff.. I tried this on my window and it worked fine

but like... yeaaaaa
avatar
Batguano
Ninja

Posts : 101

Back to top Go down

Re: C++ Part 1

Post by Unchained on Mon Jan 25, 2010 5:03 am

but like... yeaaaaa

What?
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Admin on Mon Jan 25, 2010 5:07 am

Annie wrote:I like my mac but like... I prefer my windows for programming stuff.. I tried this on my window and it worked fine

but like... yeaaaaa
avatar
Admin
Pirate King

Posts : 559

Back to top Go down

Re: C++ Part 1

Post by Batguano on Mon Jan 25, 2010 5:52 am

I like that squirrel
avatar
Batguano
Ninja

Posts : 101

Back to top Go down

Re: C++ Part 1

Post by Unchained on Mon Jan 25, 2010 6:02 am

So did this help at all?
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Paul on Tue Jan 26, 2010 4:37 am

What is the problem with Xcode?

What doesn't work? / What can't you figure out?
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: C++ Part 1

Post by Batguano on Tue Jan 26, 2010 4:54 am

another_pd wrote:What is the problem with Xcode?

What doesn't work? / What can't you figure out?


anything >_< I'm just gonna use my windows... it actually works better than xcode i think xD
avatar
Batguano
Ninja

Posts : 101

Back to top Go down

Re: C++ Part 1

Post by Paul on Tue Jan 26, 2010 4:56 am

Well, did it install?

Did you find the application?

If so, what happened when you started the application?


Last edited by another_pd on Tue Jan 26, 2010 4:58 am; edited 1 time in total
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: C++ Part 1

Post by Unchained on Tue Jan 26, 2010 4:57 am

What are you currently working on?
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Batguano on Tue Jan 26, 2010 5:01 am

I have my windows and mac running right next to each other and I have the windows visual thing on my windows and xcode on my mac

also

avatar
Batguano
Ninja

Posts : 101

Back to top Go down

Re: C++ Part 1

Post by Paul on Tue Jan 26, 2010 5:06 am

Is the image supposed to be just the upper sliver of your screen?
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: C++ Part 1

Post by Unchained on Tue Jan 26, 2010 5:06 am

I see the whole thing. Its showing her CPP and H file.
avatar
Unchained
Mod

Posts : 448

Back to top Go down

Re: C++ Part 1

Post by Paul on Tue Jan 26, 2010 6:09 am

I hope I've fixed the problem now Wink
avatar
Paul
Pickaxe

Posts : 611

Back to top Go down

Re: C++ Part 1

Post by Batguano on Tue Jan 26, 2010 6:11 am

yuhp Very Happy
now to try it on my windows once these files finish downloading <___<
avatar
Batguano
Ninja

Posts : 101

Back to top Go down

Re: C++ Part 1

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

CMPC :: Computing :: Programming :: C++

 
Permissions in this forum:
You cannot reply to topics in this forum