arrow_upward

Pages (2):
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.
#2
it is a great effort by you.  i appreciate it very much,
i would like to add something in your tutorial.
1st) I think you should include the full header file as this is a beginners  level tutorial
#include <iostream.h>

2nd) use the main function as void main() instead of int main() because the users might get error if they forgot to return an int. or even worse if they don't realize that they only have to return int. for a function defined as int type

3rd) Please include the importance of  "<<" in cout << "Hello, anon!" << endl; that why it "<<" not ">>"

OSM WORK

Best Regard
#3
(10-01-2015, 09:59 AM)Rishabh-Jain Wrote: it is a great effort by you.  i appreciate it very much,
i would like to add something in your tutorial.
1st) I think you should include the full header file as this is a beginners  level tutorial
#include <iostream.h>

2nd) use the main function as void main() instead of int main() because the users might get error if they forgot to return an int. or even worse if they don't realize that they only have to return int. for a function defined as int type

3rd) Please include the importance of  "<<" in cout << "Hello, anon!" << endl; that why it "<<" not ">>"

OSM WORK

Best Regard

int main is what is most used in C++ examples from what I have seen. I also use int main since I need to return 1 when there are errors. (or exit(-1))

It's also common sense that if "<<" is the one in the example, then it is the correct one. And that ">>" would be a different one. Like how "and" and "end" sounds alike but is totally different.
http://FreeVPS.club - Free VPSs!
#4
the function typing is very important, if you do void main() you do not need to return a string. but if you do int main() an integer is must to return from the function which might be a problem if new learners do not understand this. if you read carefully i mentioned in my previous post

there is a particular meaning of ">>" and "<<" in the language, ">>" is used for output and "<<" is used fir input, so it's better to be clear about this
(10-03-2015, 06:16 PM)Conan Wrote:
(10-01-2015, 09:59 AM)Rishabh-Jain Wrote: it is a great effort by you.  i appreciate it very much,
i would like to add something in your tutorial.
1st) I think you should include the full header file as this is a beginners  level tutorial
#include <iostream.h>

2nd) use the main function as void main() instead of int main() because the users might get error if they forgot to return an int. or even worse if they don't realize that they only have to return int. for a function defined as int type

3rd) Please include the importance of  "<<" in cout << "Hello, anon!" << endl; that why it "<<" not ">>"

OSM WORK

Best Regard

int main is what is most used in C++ examples from what I have seen. I also use int main since I need to return 1 when there are errors. (or exit(-1))

It's also common sense that if "<<" is the one in the example, then it is the correct one. And that ">>" would be a different one. Like how "and" and "end" sounds alike but is totally different.
#5
A good guide
I know html css php mysqli
I now want to learn the language C ++
#6
(10-06-2015, 05:41 PM)www111 Wrote: A good guide
I know html css php mysqli
I now want to learn the language C ++

mysqli is not a language but a library, you might consider learning PDO before jumping to another language because PDO is far more secure then any mysqli or mysql functions and you can use same PDO classes to use to connect any DB
#7
Ah, C++ Big Grin
My first programming project in college is about: Build a command-line game about "The Hidden Words" with C++
For reference, grab this .cpp and build with VS: http://pasted.co/8a6eaf34
My love about programming has starting from there, haha.
VIP Linux VPS 2$/month (25$/year 60$/2 years)
1 GB RAM 20 GB Storage 500 GB Bandwidth(50Mbit) 1 core 1 IPv4 1 IPv6
facebook.com/SnoOpyMinhThang
snoopy-xserver.com
#8
hello
first of all, that is int main() or int main(int argc, char** argv) or int main(int argc, char* argv[])
void main() give's error boath in C and C++
but if you do not type return 0; you will get just a warning
second, you must do
#include <iostream>
instead of including iostream.h
now, this is the hello world application which every programmer write's
#include <iostream>
using namespace std;
int main()
{
cout << "hello world!\n";
return 0;
}
now, you can omit using namespace std;
but instead of that you must write std:: cout <<"hello world\n";
note: \n is a new line
and, every text must be inside quotations
thanks
#9
my first c++ apps it showup "hello world" sentences.
if youre can show "Hello world" as output on your program, whatever programing language is. you re become programmer already Big Grin
Many thanks to Abc-Hosters LLC and post4vps for the VPS 3  Party


- Sorry for my bad English

#10
@maroon93 You just bumped almost a year topic lol

Please take note of the last replied date before bumping, and only bump if it was really necessary.
Thanks to ShadowHosting and Post4VPS for my VPS 5!
Pages (2):
lockThread Closed 


Possibly Related Threads…
Thread
Author
Replies
Views
Last Post

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