Welcome back.
Now that we've got Visual Studio code installed and the extensions installed, what we're going to do
is create a folder structure so that we can create different projects all within the same root folder.
That's just going to make it very efficient for us to work.
So I've already created a folder and let me show it to you.
It's right on my desktop and I created this folder called Section X.
The idea being if you're working on section one or two or three of the course, you can create your
own Section one, Section two, and Section three folders.
So this could represent any one of them.
It's an empty folder.
There's nothing in there right now.
So what I want to do is I want to open that folder in Visual Studio code so I can choose open folder
or open or I could go to file open.
So I'm just going to click open folder and go to my desktop and select that section x folder.
And I'm going to open it.
So now it's going to open up an X code.
And you can see right here there's the folder, there's nothing inside of it.
We just make this window a little bit wider so we can see it a little bit better.
So the idea is now that I want to create subfolders in there and each one of those subfolders corresponds
to a different project.
So the way we do that is we can click this icon right here, that's the new folder icon, and I just
clicked it and I'm going to type Project one.
That's the name of that folder, which is also going to be the name of my first project.
And then within that I want to select this icon right here, new file and that's going to be Main CP,
that is going to be my C++ program.
That's what we're going to build and run.
So this font is a little bit small because I just installed this.
Let me just increase it a little bit.
And the way I did that was just command plus.
All right, so let's write a really, really simple C++ program here and then we'll configure those
extensions so that they can build and run it.
So let's start with something LB Include IO stream that allows us to do input and output.
We're going to say using namespace standard and now we're going to create the main function.
If, if this looks foreign to you and you've just started the course, don't worry, that's perfectly
normal.
Just follow along, type along.
The whole point of these lectures is to make sure we've got the environment set up correctly.
All the syntax and everything you're seeing is going to be explained in the course.
So at this point, what we're going to say is going to say, see out hello from Project one and we'll
put an end line at the end to give us a new line and we return zero from Main to indicate that everything's
good.
And I just saved that with command desk's.
First thing we're going to do is we're going to set up IntelliSense.
IntelliSense is a little program that runs alongside Visual Studio code that watches what we're typing,
and it tries to give us suggestions and it shows us when we have errors and it's very, very handy.
So let's set that up.
And the way we do that, we come up to view and then command palette.
We can also use shift command p.
And that's going to give us a bunch of options here.
And if you just type C plus plus at the top, what we're looking for is this guy right here, C, C++,
edit configurations UI.
We need to make a couple of changes to that.
So I'm going to open that up and I'm going to come right down here to where it says compiler path.
And if I bring that back a little bit so I can see this little arrow down here, I want to change that
to G plus plus.
So I want to choose G plus plus right there.
That's the compiler that's going to be used.
And then I'm going to scroll down just a little bit more until I get to the C++ standard.
And there I want to select C++ 17.
That's it.
That's all we need to do.
And if you save this and I'm saving right now with commands.
Now notice what's happened here over on the left hand side.
A folder was automatically created called VS Code.
And inside that folder there's a file called CP Properties JSON.
That file contains the configuration information for what we just did.
So now what we need to do is we need to set up a build task that will execute and build our program.
And the first thing we have to do in order to do it, we have to select that main CP file.
This is very important.
Every time that we need to build something in Visual Studio code, we need to select that main file
that we're trying to build.
So we need to define that build task so we can come up to terminal and select configure default, build
task, and I'll select that.
And then it's going to ask us what build system are you using?
What compiler are we using?
Well, we're using G plus plus.
You can see it right here.
I'm going to select that now.
It's created a new file.
You can see it over here on the left.
It's called Tasks JSON and it contains configuration information for how Visual Studio code is going
to build our project.
Now, we need to make a few changes to this file right here on line nine.
You'll see this sorry.
On line eight, you'll see this args section.
These are the arguments that are sent to the compiler and we're going to add a couple.
So right after line nine, right after the minus G option, we're going to put in dash wall with a capital
W lowercase alpha that tells the compiler to generate all warnings.
Then we're going to add one more standard equals C plus plus 17 and that's dash STD equals C plus plus
17.
That tells the compiler to use the C++ 17 standard.
And there's one more thing we need to do is we're going to change this line 12 right here.
We're going to change that file to this name, file name.
So what I'm going to do is I'm just going to copy that and I'm going to paste it right in here.
And then right after that, curly that closed curly brace, I'm just going to do slash star CP that
tells the compiler to compile all the C++ files into folder by default.
Visual Studio code will only compile one file.
We only have one there now, but we'll have more than one later in the course.
So we want to be sure that we're compiling all of them.
That's it.
Those are the changes we need to make at this point.
We can save.
I just saved with command s and we can close this down.
Now we're ready to build our program.
So remember what I told you.
First thing you need to do is select the main CP file that you want to build.
There may be and there will be many, many projects in here.
We'll have project one, Project two, each one of them will have its own main CP.
So we have to be sure that we select the one that we want to build, and then we're going to come up
to terminal and run build task.
You can also do shift command B when we do that, the compiler will build the executable file that we
want to run.
So I'm going to click that now.
And you can see the output right here.
Notice we're using the G plus plus compiler.
There's that minus G minus wall minus standard C plus plus 17.
We entered there's the star CP we entered and it's building main in project one folder.
That's exactly what we want builds finished successfully.
So if you notice a file was created over here, right there, that main file, that is our executable
file.
That's the file we can run.
That's the file that's going to say hello from Project one when we execute it.
How do you execute it?
Real simple.
I'm just going to close this here to give me a little bit more room and I am going to right click on
that and then say Open an integrated terminal.
And it's just opened that folder for me.
And if I type LLS, it'll give me a listing of the files in that folder.
And you can see you can see Main, you can see Main CP and you also see this main symbol file.
That's something that the compiler generates.
So if we want to run this program, we need to run main.
We do a dot slash main.
That dot slash is really important.
So always use dot forward slash and then the name of the executable.
And when I press enter, we should see hello from Project one.
And there it is.
That's exactly what we expected.
Pretty cool.
Pretty easy.
Now, suppose I want to create another project right under here.
If I click on that folder icon right there to create a new folder, it won't do what I want.
What it'll do is it'll create that new folder underneath Project one.
That's not what I want.
I want Project two to be at the same level as Project one.
Intuition says, Come on up here and click it, right?
But that doesn't really work.
So it's not too intuitive.
But the way that you do it is you can select Project one and then just hit escape.
So you see, I just press the escape key and I got this blue box.
Now I can click on that folder and create a new project called Project two, and it's going to be at
the same level as Project one.
Now I can create my main CP file in here.
And I can write another program and I'm actually not going to write it.
I'm just going to copy this program since it's almost the same.
So I'm just going to copy this program from here right into here, and we'll just make one change.
We'll say project two.
That's pretty easy.
Now, if we run this, remember we have to build it first.
We have to select which one we want to build, what we want to build project to.
So make sure you select the main in project two.
We don't want to select the main and Project one.
We've already done that one.
So I'm going to select that and then I'm going to build.
So I'm going to go to terminal and select run the build task and we're done.
You can see Build finished successfully.
Project Two's main was created and there it is right here.
So if I want to execute that, I can just open in the integrated terminal.
We can do ls again if we want.
There it is.
And we do dot slash main and it's going to say hello from Project two.
Pretty easy.
We can modify this program slightly to get input from the user.
Let's do that.
Let's say we have an integer and we'll call that integer favorite number just like that.
And then we'll keep this.
Hello from Project two in there.
But let's also ask the user to enter their favorite number.
So we're going to say enter your favorite number.
Then we're going to read that number into the favorite number variable.
And now we're going to display and now we're going to display.
Your favorite number is the number that just enter
and we'll add a new line at the end.
That's it.
So we've just modified that program slightly.
If we execute Main now, the old program is going to run because we haven't built the new one yet.
Right.
These updates are not in this main executable yet.
That's why we need to build it.
So we're going to select our main CPP and I'm going to select Terminal.
Run the bill task.
We have a successful build.
Now I can come over here to my main right, click on it, open it in the terminal, and we could just
run it.
Hello from project two.
Now it's asking me entry.
My favorite number.
Well, my favorite number let's say is 34.
I'll hit enter.
It says your favorite number is 34.
Simple as that we can create as many projects as we like.
Once our tasks, JSON and our CP properties JSON files are configured, then we can create as many as
we want.
We don't have to touch those again.
They'll apply to all the subprojects.
So in the next video, I'll show you how to use the debugger and how to configure the debugger so that
we can walk through our code one line at a time and inspect our variables and their values as we execute
the code.
It's a very, very handy tool that we can use to help us program.
I'll see you in the next video.