Welcome back.
Now that we've got Visual Studio code installed and the C++ extension installed, we can now start creating
C++ projects that we can build and run within Visual Studio code.
So first thing we need to do is we need to create a folder.
I'm going to create the folder, not within V's code.
I'm going to create it right on my desktop.
So I'm just going to come over here to my desktop and I'm going to create a new folder and I'm just
going to call it section X.
The idea being that whatever section you're working on, you can create a Section five, Section six,
Section seven, folder and so forth.
So this could represent any folder.
We'll create it.
And I'll close this up.
Then we want to go into Visual Studio code and open that folder we just created.
We can click the blue button here.
If this is open, we can also hit control O, Control K and so forth.
Or we can come up here to file open folder right there.
So I'll just do that.
And I'm going to select the folder I just created on my desktop, section X and I'll press.
Okay.
And now you can see that that folder has been open.
It's right here, section x, there's nothing in it right now.
It's just an empty folder and this getting started page.
I'm just going to close that to get that out of the way.
Perfect.
So now what we need to do is we need to create a folder within this folder.
This is the top level folder so we can do that by selecting that icon right there, which is new folder.
And I'm just going to call this project one.
So this would be my project one folder, the idea being that we can create multiple project folders
within this section X folder.
Now once we do that, we need to create a C++ program that we'll be able to run, and we want to do
that within Project one.
So we want to be sure that Project one is selected and I'm going to press this icon right here for new
file and I want to create Main CP, that's our C++ program.
When I select that, it opens up on this site here.
And what I want to do here is I want to write a really simple C++ program and I'm going to do a pound
include IO stream.
A lot of this won't make sense to you if you're just starting the course.
That's okay.
Just follow along, type along, and this will all be explained as the course progresses.
Then we're going to say using namespace standard and now what we're going to do is we're going to create
the main function.
So we'll say int main and we'll just do a display statement, rule something really simple, we'll just
say C out and hello from Project one and we'll put a new line at the end and finally we'll return zero.
As I said, the syntax will be explained as the course progresses.
Now I'm going to save that.
So I'm just going to come to here file, save or control this.
We can't run it quite yet.
We've got to do a little bit of configuration which is going to help us build and run this project.
So there's two things we need to do.
First, we need to configure IntelliSense.
That's the piece of software that runs in Visual Studio code that kind of watches you as you type.
And it's trying to help you with ideas and suggestions and finding mistakes as you go.
So we could go to view command palette.
And then what we wanted to do right in here, we want to just type C++ and find this.
Edit configurations UI C, C++, edit configurations UI.
It might be somewhere down here.
In this case, it showed up right up here for me.
So I just want to select that and we're going to make a couple of small changes to this.
First of all, go to the compiler path and be sure that you don't have DCC, but we want G plus plus.
We want g plus plus we want to use a C plus plus compiler, not the C compiler.
So you want to be sure that that's there.
And then we want to come down to the C++ standard and we want to use C++ 17.
There we go.
That's it.
So now we can file, save that file and we can close that up because we're done with that.
Now you'll notice what happened over here on the left side, a vs code folder was created and that folder
contains a file called CP Properties JSON and that file contains the configuration information for IntelliSense.
What we just said up perfect.
So next step is to create a default build task.
That's what's going to compile the code and build it.
So in order to do that, we want to come to terminal and select configure default, build test right
here at the bottom.
And at this point it's asking you, Hey, what compiler are you using?
Be sure to select the G plus plus option, not CPP or anything else, just g plus plus.
You may have several different versions like I do just select C++ and it will use the most recent version.
So I'll do that.
And now I get this file that pops up.
We need to make a few small changes to this file so we can configure the build.
I'm coming here to line nine in the ARGs section and I just want to add right after the minus G, I
want to add minus or dash capital W a LX and the alpha is in lowercase followed by a comma that tells
the build to display all warnings.
Then we need to do dash std equals C plus plus 17 with a comma at the end.
Again, that tells the build system to use the C++ 17 standard.
And we've got one more small change right here.
We want to change line 12 from file to file your name.
So what I want to do is I want to copy that and paste it right in here.
Just like that.
So now we've got file journey and we still have the dollar sign in the curlies, but we want to change
file to file your name.
So the next thing we want to do is we want to add a slash forward slash star.
CP Right after that closed curly this tells the build system to build all the C++ files in that project
by default.
Visual Studio code when it comes configured.
It only does the one file.
So as we build projects that get bigger, we're going to have multiple C++ files.
So it's really important that we do that.
So I'm going to control S to save and I'm going to close that down.
And now we're ready to build and run this program.
So what do we do first?
It's very important that we select the C++ file that we want to build within the right project.
It's possible that we'll have multiple projects and every project will have its own C++ file.
That has to be selected because the Build System and Visual Studio code will build the active file,
which is the one that's been selected.
So once we have that selected, we can come up to terminal and run, build task or control shift B And
what will happen is right down here you can see the output of the bill that says build finished successfully.
You can also see our GPUs plus compiler being executed with those options that we typed into our tests,
JSON.
And you can also see that it's using the project one folder and it's compiling all the star CP files.
So it's exactly what it's doing, exactly what we told it to do.
So now we have an executable that we can run and that executable is called Main and it's right here
in the project.
Before we only had the one source file.
Now we've got the executive file.
So how do we run that?
Let me close this up and just make a little bit more room.
We can right click on that file.
And select open and integrated terminal that will open up a terminal window down here and notice it's
in the project one folder.
That's exactly where we want to be.
And if you type else, that will list the files in that directory.
And you can see there's my main CP and there's my main executive.
It's green.
So if I want to run this program, all I need to do is type dot forward slash main.
Really important that you use the dot forward slash so you can find it.
And when we press enter, we expect this to display hello from Project one.
So let's do it.
And that's exactly what we get from Project one.
So there you go.
This shows you how to set this up so that it can build and run C++ projects.
Right now we only have the one project, project one.
So let's create another project.
We need to create a new folder.
The problem is, if we create a new folder right now, it's going to create an underneath project one.
That's not what I want.
I want Project two to be at the same level as Project one, and it's not really intuitive as to how
you would do that.
You would think, Well, you select this one, but then the folders go away.
So the way to do it is just select Project one and then press escape.
And when you press escape, notice what happens.
You get this blue bounding box here going around.
Now when you create the folder, you can type in project two or whatever you like, and it's at the
same level as Project one.
That's exactly how you would do that.
We can create as many project folders as we need.
Now, in Project two, I need to create my C++ file, so I'll select new file and type in main CP.
And what I want to put in here is let's put in the same thing that we had here.
I'm just going to copy and paste this so that I don't have to type it all in again.
So I'm just going to select it all and I'm going to copy and I'm going to come back to Project Two's
main and paste it in here.
There we go.
Let me close this window up down here.
Give us a little bit more room.
And all I'm going to do here is say hello from Project two and I'll control S to save this.
So now if I want to build this project project to, I have to select that.
If you select this or this and try to do a build, you're going to get all kinds of weird things happening
because it doesn't know what to do.
So we want to select the C++ file within Project two.
And again, we want to go to terminal and we want to the build task.
And notice we get exactly the same thing build finish successfully.
Except you can see it's working on Project two now and we created an executive file in Project two.
Project one was not affected.
So if we want to run this file, we can right click on it, open it in the Integrated Terminal.
Notice we're in Project two folder now.
We could just do that dot slash main and we expect now to say hello from Project two and that's exactly
what we get.
So that's it.
That shows you how to create folder structures, create C++ files, build and run the active tasks.
We can add as many projects as we like inside this folder, this section, X folder, and it's a real
handy way to keep yourself organized in the next video.
What we'll do is I'll show you how to set up Visual Studio code so that we can debug C++ projects.
Debugging is really important and helps us find errors and understand our code better.
And the idea with the debugger is that we can execute our code one line at a time and we can jump around
between pieces of code and we can actually see the values of our variables as we're executing the code.
So it's a very, very powerful tool to have in our tool belt.
So I'll see you in the next video and we'll do that.