arrow_upward

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Explaining your first program! [C++]
#1
So, you're interested in C++, huh?

Whatever the reason may be, I'm going to send you down the very boring start of learning C++.

(Please note that this is my first tutorial, and all feedback is accepted.)

First, I'd recommend grabbing Eclipse. (It helps identify many errors you'll end up making. Also, look up a few tutorials on getting it set up for C++)

Maybe you don't want to use Eclipse, aren't allowed to download anything, or are on a Chromebook for school. If so, here's a website inferior, yet useful for C++.

Now that you're on Eclipse (or cpp.sh) let's set up our first program.
[Image: q5aM7LW.png]

I'm making these images as opposed to code due to the ability to copy. I'd much rather you type this out then copy+paste. Trust me, you'll be typing this a ton.

Now, allow me to explain what this all does.

#include - includes other C++ libraries (i.e. iostream, iomanip, string)
<iostream> - Library for the "stream" (i.e. 'blah << blah << blah;')

using namespace std - Using Namespace Standard: Consider this a shortcut for later. It's a good idea to get in the habit of adding this to your program so typing something like 'string' doesn't have to be: 'std:Confusedtring'

int - integer type
main - Function needed in order to run the program

return 0 - Needed in order to end the program.


Now, don't worry if you don't recognize the majority of this, or if it doesn't click automatically. You'll learn more integer types, more functions, and more variables.

Let's make this program do something:
[Image: L05NAYs.png]

Take a second, try to guess what this program will do.

Now, run it! (On Eclipse, save/build/run)

It will simply print out:
Hello, anon!

In your console. Let's explain why it does this. Let's look closer at that line:
[Image: j8hIe7l.png]
cout - Well, you see a word that we're familiar with in there, "out" but, what does 'c' stand for? Can you guess it? The 'c' stands for console. Then just add our definition for the word out! So, basically, it uses the console to output into the program. In this case, we outputted a string, which is our "Hello, anon!" 

endl; - Let me explain here, because I haven't yet. If you haven't noticed, things in C++ often times end with a semicolon(Wink. 'endl;' in particular uses two English words! 'end' and 'line'. Now you can probably assume what it does.

Left for modification, I will add tons more to this simple tutorial later. For now, I just want it here so I don't accidentally delete it.
lockThread Closed 


Messages In This Thread
Explaining your first program! [C++] - by paronte - 10-01-2015, 04:09 AM

Possibly Related Threads…
Thread
Author
Replies
Views
Last Post

person_pin_circle Users browsing this thread: 2 Guest(s)
Sponsors: VirMach - Host4Fun - CubeData - Evolution-Host - HostDare - Hyper Expert - Shadow Hosting - Bladenode - Hostlease - RackNerd - ReadyDedis - Limitless Hosting