Explaining your first program! [C++] - Printable Version +- Post4VPS Forum | Free VPS Provider (https://post4vps.com) +-- Forum: Geek World (https://post4vps.com/Forum-Geek-World) +--- Forum: Scripting & Programming (https://post4vps.com/Forum-Scripting-Programming) +--- Thread: Explaining your first program! [C++] (/Thread-Explaining-your-first-program-C) Pages:
1
2
|
Explaining your first program! [C++] - paronte - 10-01-2015 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. 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:tring' 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: 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: 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(. '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. RE: Explaining your first program! [C++] - Rishabh Jain - 10-01-2015 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 RE: Explaining your first program! [C++] - Conan - 10-03-2015 (10-01-2015, 09:59 AM)Rishabh-Jain Wrote: it is a great effort by you. i appreciate it very much, 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. RE: Explaining your first program! [C++] - Rishabh Jain - 10-05-2015 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, RE: Explaining your first program! [C++] - www111 - 10-06-2015 A good guide I know html css php mysqli I now want to learn the language C ++ RE: Explaining your first program! [C++] - Rishabh Jain - 10-07-2015 (10-06-2015, 05:41 PM)www111 Wrote: A good guide 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 RE: Explaining your first program! [C++] - SnoOpy - 01-08-2016 Ah, C++ 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. RE: Explaining your first program! [C++] - brightening-eyes - 01-15-2016 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 Code: #include <iostream> now, this is the hello world application which every programmer write's Code: #include <iostream> 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 RE: Explaining your first program! [C++] - maroon93 - 11-24-2016 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 RE: Explaining your first program! [C++] - Honey - 11-24-2016 @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. |