Hello everyone and welcome, I’m Master Jake. And this is going to be my first tutorial on C++. I’m not doing a web programming at the moment because I’m focusing on this. I will do more web programming tutorials later—pretty soon actually. But I’m going to go ahead and start this video and try to get a few of these out just so I can teach everyone a little bit about it.
So the first thing you need to know about C++ is that it’s a fairly difficult thing which you need to be well prepared before you start learning it. Ands you’ll need a compiler, there are couple that I recommend, the first is Microsoft Visual C++ 2008 Express Edition, I will write that down. You type that in on Google and you’ll get a link and it’s free to download. And the next on C++ by Bloodshed, I think that’s how you spell that and you can also Google that and it is also free. They’re both a really good programs.
I’ve noticed when I compile my executive builds on 2008 Express, I sometimes—when I send them to people, they can’t use them but when I compile with Dev, everyone can use them so. I’ve been using it more often even though I kind of like the interface of Microsoft Visual C++ a little bit better.
But go grab a compiler and then you need to open it. I'm going to be showing you on Dev, you can use Microsoft or any other compiler just as long as you know how to start projects and stuff. So you’ll need to find the file new project or whatever. Find how to start a new project, it shouldn’t be that difficult. And we’re going to open a project and what you want to do is find empty project—now this might be on a—if you’re using Microsoft Visual C++ you’ll need to select the console application and then, after the screen pops up, click next and then select empty project.
Now, you want an empty project and we’re going to call it Hello World and make a C++ project and click okay. Now we need to save it somewhere, because as I said, this is different for all compilers, you’re going to open an a new folder called Hello World, and I’m going to save it as Hello World.dev. Now, you need to open a new file. I’m actually going to add a folder and call it source files and click a new button or go to a new file or whatever, different for every compiler. And we’re going rename this to main.cpp because it has to be the main.cpp file to run.
Okay, now, the first thing you’re going to want to do in all C++ programs is add all your libraries and the library is just a pre-built set of code that can help you out by giving you some built-in functions to use and there are a lot of libraries, but the main one is iostream and how you include it is you type in the number sign, the word include, space, less than sign, iostream, greater than sign. Now that would include the iosteam library and then you need to type, using name space std.
Now, I’ll show you why you need to do that in a moment, but we’re going to continue on. Now here how you start a function. You need the function type which there are many types, there’s nth, void and more and so on. But we’re going to be using is nth for main and the main function is declared by the keyword main. And it has to be called that and there has to be a main function in your program or the program won’t run. And then we’re just going to type void in here which stands for nothing because we’re not going to have any parameters so we’re going to leave that as a void. Go ahead and open a curly bracket and close a curly bracket. And now I’m going to show you a simple command called cout. Type it just like that. Then you need two less than signs and then start a quote Hello World, end you r quote and put a semi colon, you’ll notice in programming, the language is a lot of time, so you’ll need a semi-colon at the end of the line for a code line.
And I’m going to show you—well, I’m going to go ahead and show you—I have a zip compiler right now, go to execute compile and run or you have a different button to run. Okay, you see it open and close, that’s because there’s nothing stopping it, so we need to type a system, pause and you can look at how that works there. And that’s just a system command, kind of like in batch files if you’ve watched my tutorials on that, you can use a lot of commands from batch files in here. And then we need to return to zero and I’ll show you why.
Go ahead and run the file, compile and run, you see it says, Hello World press any key to continue, so that worked fine. No return zero is because all functions unless they are type void. They must return something. In this case, it has to return type integer, integer is a number and we don’t want it to return anything so we return zero, you have to have it there, or you may get compiling errors. Now, I’m going to go ahead and show you—you can string out lines by typing two more less than signs and then more strings or whatever else you would like to put on there. That’s how you connect.
I’m going to type the phrase endl which is just end and an l, and what this stands for is end line so it’s going to type the string out and it’s going to end the line—and run and you will see. Hello World, and then it breaks the line, ends then line and then press any key to continue, it paused.
So that is the basics of the C++ document, I’m going to try so I go over a little bit more on this in case you’re still confused, the reason I’m using space std is there is because if we take it out and try to compile and run, you’re going to see an error but if we type an std colon, colon, before the cout, or actually no—that didn’t work either, endl is also undefined. Okay, it does the same thing. But the point of using names for this std is it includes it automatically so you don’t have to type std, colon, colon, by a bunch of stuff. So let’s take out the std, colon, colons and just use the name space of std and that will save you a lot of time.
Yeah, that’s pretty much all you need to know for the basics of you get started, this is a simple consul application. I hope you enjoy this tutorial and if you have any questions, please email me or send me a message on YouTube and thank you for watching the video.
Transcription by:
Scribe4you Transcription Services