In this video, I'll show you how to use the source code provided for the course with Visual Studio
code.
First thing we need to do is get to the source code.
The source code is provided in the course content and you can see right now it's in section 22.
It's in a section called Extra Information Source Code and other stuff.
And if you open that up, you'll see that source code for all sections.
And it will bring you this page right here.
Don't go off of section 22.
If I add new sections to the course, that will get bumped down to 23, 24, 25.
So I'm not sure where that will be when you watch the video.
Just look for extra information, source code and other stuff.
Open that up and you'll find the source code.
Once you do that, there will be a link to a zip file for the source code for each section in the course.
And if you want to download the source code, just click on the link.
I've already done that and I've downloaded the source code for section four as a zip file and you can
see it right here.
There's the zip file right here.
What I'm going to do is I'm just going to double click on it.
And then extracts the Section four folder.
So I'm just going to select Section four and I'm just going to move it over to my desktop.
I'm just using the desktop and an example.
You can move that to any folder you wish.
What's really important is whatever folders you create, whatever names you use.
Remember, no spaces, no international characters and no special characters.
Otherwise, you may have build problems.
So now once we've got that on our desktop, you can see our previous Section X course that I created
in the previous videos.
This section for what we need to do now is we need to open up this folder within Visual Studio code.
You see, this folder has projects within it challenge solution, compiler errors, compiler warnings
and so forth.
Those will be the individual projects that will also be using within Visual Studio code.
So I'm just going to close this and I'm going to head over to Visual Studio code right here, and I'm
going to open Section four from my desktop.
Make sure you open the section four folder, not the folders within section four.
So I'll select open and there we go.
You can see that the folder structure has now been opened within Visual Studio code and it just makes
this a little bigger.
So you can see that Section four right there and within Section four you've got the projects that I
mentioned.
We also have some other files.
We have this dot code light folder and this Makefile in section four workspace and so forth.
Those are all code light files.
Don't worry about those.
You can remove them if you like, or you can just leave them in and you can use your project with Visual
Studio code or with code light.
Visual Studio code will just ignore those files.
So what do we do next?
Well, we need to configure Visual Studio code to think of this section as a C plus plus section.
Right.
So what we need to do is we need to set up IntelliSense, we need to set up our default build task.
And if we want to debug, we need to set up our launch JSON file.
There's a couple of ways we can do that.
We can do it manually, just like we did in the previous videos for this section.
And that's what I'll do here again, just so you see it one more time, or you can grab that dot vs
code folder that you've already created in those other projects and just move it into here.
Just copy it right into section four and you'll be good to go, but I'm going to do it one step at a
time, so let's do that.
So the first thing we'll do is we'll open up any one of these.
And I'm just going to open up, let's say first program and select the main CPP file within it.
That's the program we'll use to configure.
So what we'll do first is we'll go over here to view and the command palette.
We'll type C++.
And again, we're looking for C, C++, edit configurations UI right there, we'll select that and then
we want to be sure we're using C++.
So you come down to compiler path and whatever's there, just change it to G Plus.
Plus, we've got that note.
We'll scroll down a little bit further and look for the C++ 17 standard and we'll use C++ 17.
That's it.
I'm going to command S to save it and I'll close that up.
So notice now our V code folder has been set up with our CP properties JSON file, so we're good to
go here.
Now what we're going to do is set up the default build test.
So again, click on that main CP.
This time you go up to terminal and down at the bottom.
Configure default, build task.
I'll select that.
I'm going to use G plus plus, I'll select G plus plus.
And this is the file we're going to make a couple of changes in in the ARGs section here on line eight,
we're going to add dash w LX with W is capitalized and we're going to add dash speed equals C plus plus
17 to tell the compiler to use the C++ standard just like that.
If you're typing anything and you see squiggles like you're seeing right there, that means there's
a typo somewhere you might have forgotten a quote mark or a comma.
In this case, it's the comma.
Then what we'll do is we'll take this file your name and we'll copy that right into line 12 and replace
file with file your name.
And once we do that, we have to add our slash start up CP to tell the compiler to compile all the files
in there.
That's it.
So now we're done with that.
We can now build our project.
Let's try it out.
So I'm going to close this out and I'm going to open my main CP again.
Now, once I'm here, I can come up to terminal and run the build task or you can press shift command
b.
You can see down here we've got a build and it was successful.
Always double check.
You've got your minus G, your minus wall, you've got your standard C++ 17 and we've got our CP files
being compiled at that point.
Now we have this main executable that was created for us right here inside Project one.
So I can right click on that and open it in the integrated terminal.
We can do an LZ to see the files that we've got and we've got several files.
Some of them are code light files.
Don't worry about them.
This dot mkay.
And the dot project file.
But we do have our main executable right here if we want to run it.
We just type dot forward slash main and press enter enter your favorite number between one and 100,
let's say 45.
Amazing.
That's my favorite number two.
And you can see from the source code up here, that's exactly what the program is doing.
So that's it for configuring for the build.
Now, in order to configure for debugging, let me close this window here to make up a little more room.
What we can do is again, we can select our main DHCP file and we can come up to run add configuration
and select C++ gdb ltb.
And G plus plus.
Now, at this point, we're want to kill the debugger right here.
We want to use that little red square right here icon to stop it.
And what we want to do is we want to edit this launch JSON file that was created right there, which
is open already.
The only thing we want to do here is we want to change the type to LTB.
When we do that, you'll notice we have some errors just like we had before in the previous videos.
We just want to delete those lines.
We don't want any squiggles or any red markers or anything anywhere.
That's it.
Your current working directory should be filed.
Your name.
Make sure that that's correct.
If it's not, you can change it to that and that's it.
I'll save that and we'll close this up.
And now we can debug this program that's open.
So I can click on the program and then select the debugger right over here on the left, that bug play
icon run and debug.
I can select that and it's waiting for us now to execute it by clicking on that green arrow up here.
I do want to put a breakpoint in, so let's put a breakpoint right here on line seven.
You can come across here, you'll see that red dot.
There's a breakpoint showing up down here.
If you see a lot of other breakpoints from other projects, clear them out and then just come in here
and select the breakpoint you want.
At this point, we can run it, so we'll just click on that red arrow.
The debugger will engage.
This bottom bar turns orange.
You can see favorite number up here, set to zero.
We never initialized it and we'll talk about that in the class.
Our current executing line is line seven.
So we can execute it by just stepping over, by pressing this icon right here and the output will be
here in terminal.
So you can always click there.
So I'll do that and I'll do it one more time.
It's asking me now for the favorite number.
Again, I'll type 45 one more time and when I press enter now you'll see that I'm stopped at line nine
and favorite numbers value has changed to 45.
And as before, we can hover over that variable name and we can see our value to finish the program.
You can click the play arrow or you can just stop it right here in the debugger.
I'll just continue.
That's it.
So there you go.
This video shows you how to set up the source code provided for the course to work within Visual Studio
code.
So now we can edit.
We can debug and we can build and run.