1
00:00:05,370 --> 00:00:06,390
Welcome back.

2
00:00:06,420 --> 00:00:12,060
Now that we've got Visual Studio code installed and the extensions installed, what we're going to do

3
00:00:12,060 --> 00:00:18,890
is create a folder structure so that we can create different projects all within the same root folder.

4
00:00:18,900 --> 00:00:21,630
That's just going to make it very efficient for us to work.

5
00:00:21,930 --> 00:00:25,220
So I've already created a folder and let me show it to you.

6
00:00:25,230 --> 00:00:29,530
It's right on my desktop and I created this folder called Section X.

7
00:00:29,550 --> 00:00:34,050
The idea being if you're working on section one or two or three of the course, you can create your

8
00:00:34,050 --> 00:00:36,990
own Section one, Section two, and Section three folders.

9
00:00:36,990 --> 00:00:39,110
So this could represent any one of them.

10
00:00:39,120 --> 00:00:40,290
It's an empty folder.

11
00:00:40,290 --> 00:00:41,610
There's nothing in there right now.

12
00:00:41,610 --> 00:00:47,940
So what I want to do is I want to open that folder in Visual Studio code so I can choose open folder

13
00:00:47,940 --> 00:00:50,280
or open or I could go to file open.

14
00:00:50,280 --> 00:00:55,800
So I'm just going to click open folder and go to my desktop and select that section x folder.

15
00:00:56,480 --> 00:00:57,560
And I'm going to open it.

16
00:00:57,560 --> 00:00:59,330
So now it's going to open up an X code.

17
00:00:59,330 --> 00:01:02,570
And you can see right here there's the folder, there's nothing inside of it.

18
00:01:02,660 --> 00:01:06,110
We just make this window a little bit wider so we can see it a little bit better.

19
00:01:06,470 --> 00:01:12,530
So the idea is now that I want to create subfolders in there and each one of those subfolders corresponds

20
00:01:12,530 --> 00:01:14,030
to a different project.

21
00:01:14,150 --> 00:01:20,660
So the way we do that is we can click this icon right here, that's the new folder icon, and I just

22
00:01:20,660 --> 00:01:22,640
clicked it and I'm going to type Project one.

23
00:01:22,640 --> 00:01:27,560
That's the name of that folder, which is also going to be the name of my first project.

24
00:01:27,560 --> 00:01:35,120
And then within that I want to select this icon right here, new file and that's going to be Main CP,

25
00:01:35,870 --> 00:01:38,720
that is going to be my C++ program.

26
00:01:38,720 --> 00:01:40,520
That's what we're going to build and run.

27
00:01:40,520 --> 00:01:43,400
So this font is a little bit small because I just installed this.

28
00:01:43,400 --> 00:01:45,350
Let me just increase it a little bit.

29
00:01:45,350 --> 00:01:47,540
And the way I did that was just command plus.

30
00:01:48,320 --> 00:01:53,720
All right, so let's write a really, really simple C++ program here and then we'll configure those

31
00:01:53,720 --> 00:01:55,940
extensions so that they can build and run it.

32
00:01:55,940 --> 00:02:03,380
So let's start with something LB Include IO stream that allows us to do input and output.

33
00:02:03,860 --> 00:02:09,320
We're going to say using namespace standard and now we're going to create the main function.

34
00:02:09,889 --> 00:02:14,540
If, if this looks foreign to you and you've just started the course, don't worry, that's perfectly

35
00:02:14,540 --> 00:02:15,080
normal.

36
00:02:15,080 --> 00:02:16,640
Just follow along, type along.

37
00:02:16,640 --> 00:02:20,540
The whole point of these lectures is to make sure we've got the environment set up correctly.

38
00:02:20,540 --> 00:02:24,320
All the syntax and everything you're seeing is going to be explained in the course.

39
00:02:24,320 --> 00:02:32,120
So at this point, what we're going to say is going to say, see out hello from Project one and we'll

40
00:02:32,120 --> 00:02:38,420
put an end line at the end to give us a new line and we return zero from Main to indicate that everything's

41
00:02:38,420 --> 00:02:38,810
good.

42
00:02:38,810 --> 00:02:40,940
And I just saved that with command desk's.

43
00:02:41,510 --> 00:02:44,000
First thing we're going to do is we're going to set up IntelliSense.

44
00:02:44,000 --> 00:02:50,150
IntelliSense is a little program that runs alongside Visual Studio code that watches what we're typing,

45
00:02:50,150 --> 00:02:54,710
and it tries to give us suggestions and it shows us when we have errors and it's very, very handy.

46
00:02:54,710 --> 00:02:56,030
So let's set that up.

47
00:02:56,030 --> 00:03:00,470
And the way we do that, we come up to view and then command palette.

48
00:03:00,470 --> 00:03:02,960
We can also use shift command p.

49
00:03:03,710 --> 00:03:05,980
And that's going to give us a bunch of options here.

50
00:03:05,990 --> 00:03:12,440
And if you just type C plus plus at the top, what we're looking for is this guy right here, C, C++,

51
00:03:12,440 --> 00:03:14,510
edit configurations UI.

52
00:03:14,540 --> 00:03:16,790
We need to make a couple of changes to that.

53
00:03:16,790 --> 00:03:21,980
So I'm going to open that up and I'm going to come right down here to where it says compiler path.

54
00:03:21,980 --> 00:03:26,990
And if I bring that back a little bit so I can see this little arrow down here, I want to change that

55
00:03:26,990 --> 00:03:28,430
to G plus plus.

56
00:03:29,160 --> 00:03:31,620
So I want to choose G plus plus right there.

57
00:03:32,070 --> 00:03:34,230
That's the compiler that's going to be used.

58
00:03:34,470 --> 00:03:38,970
And then I'm going to scroll down just a little bit more until I get to the C++ standard.

59
00:03:39,090 --> 00:03:42,840
And there I want to select C++ 17.

60
00:03:43,440 --> 00:03:43,890
That's it.

61
00:03:43,890 --> 00:03:44,700
That's all we need to do.

62
00:03:44,700 --> 00:03:47,960
And if you save this and I'm saving right now with commands.

63
00:03:49,600 --> 00:03:52,270
Now notice what's happened here over on the left hand side.

64
00:03:52,450 --> 00:03:55,930
A folder was automatically created called VS Code.

65
00:03:56,140 --> 00:04:00,310
And inside that folder there's a file called CP Properties JSON.

66
00:04:00,700 --> 00:04:04,590
That file contains the configuration information for what we just did.

67
00:04:04,600 --> 00:04:11,230
So now what we need to do is we need to set up a build task that will execute and build our program.

68
00:04:11,230 --> 00:04:16,410
And the first thing we have to do in order to do it, we have to select that main CP file.

69
00:04:16,420 --> 00:04:17,860
This is very important.

70
00:04:17,860 --> 00:04:24,070
Every time that we need to build something in Visual Studio code, we need to select that main file

71
00:04:24,070 --> 00:04:25,210
that we're trying to build.

72
00:04:25,600 --> 00:04:32,800
So we need to define that build task so we can come up to terminal and select configure default, build

73
00:04:32,800 --> 00:04:34,690
task, and I'll select that.

74
00:04:34,690 --> 00:04:37,720
And then it's going to ask us what build system are you using?

75
00:04:37,720 --> 00:04:39,190
What compiler are we using?

76
00:04:39,190 --> 00:04:41,200
Well, we're using G plus plus.

77
00:04:41,200 --> 00:04:42,340
You can see it right here.

78
00:04:42,340 --> 00:04:44,920
I'm going to select that now.

79
00:04:44,920 --> 00:04:46,090
It's created a new file.

80
00:04:46,090 --> 00:04:47,350
You can see it over here on the left.

81
00:04:47,350 --> 00:04:54,550
It's called Tasks JSON and it contains configuration information for how Visual Studio code is going

82
00:04:54,550 --> 00:04:55,870
to build our project.

83
00:04:56,260 --> 00:04:59,860
Now, we need to make a few changes to this file right here on line nine.

84
00:04:59,860 --> 00:05:01,180
You'll see this sorry.

85
00:05:01,180 --> 00:05:03,460
On line eight, you'll see this args section.

86
00:05:03,460 --> 00:05:06,970
These are the arguments that are sent to the compiler and we're going to add a couple.

87
00:05:06,970 --> 00:05:14,440
So right after line nine, right after the minus G option, we're going to put in dash wall with a capital

88
00:05:14,440 --> 00:05:20,410
W lowercase alpha that tells the compiler to generate all warnings.

89
00:05:20,710 --> 00:05:29,530
Then we're going to add one more standard equals C plus plus 17 and that's dash STD equals C plus plus

90
00:05:29,530 --> 00:05:30,310
17.

91
00:05:30,310 --> 00:05:33,550
That tells the compiler to use the C++ 17 standard.

92
00:05:34,060 --> 00:05:37,690
And there's one more thing we need to do is we're going to change this line 12 right here.

93
00:05:37,690 --> 00:05:41,770
We're going to change that file to this name, file name.

94
00:05:41,860 --> 00:05:45,850
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.

95
00:05:46,750 --> 00:05:53,800
And then right after that, curly that closed curly brace, I'm just going to do slash star CP that

96
00:05:53,800 --> 00:05:59,050
tells the compiler to compile all the C++ files into folder by default.

97
00:05:59,050 --> 00:06:01,570
Visual Studio code will only compile one file.

98
00:06:01,570 --> 00:06:04,780
We only have one there now, but we'll have more than one later in the course.

99
00:06:04,780 --> 00:06:07,000
So we want to be sure that we're compiling all of them.

100
00:06:07,630 --> 00:06:08,110
That's it.

101
00:06:08,110 --> 00:06:10,360
Those are the changes we need to make at this point.

102
00:06:10,360 --> 00:06:11,260
We can save.

103
00:06:11,260 --> 00:06:14,770
I just saved with command s and we can close this down.

104
00:06:14,860 --> 00:06:16,840
Now we're ready to build our program.

105
00:06:16,840 --> 00:06:18,790
So remember what I told you.

106
00:06:18,820 --> 00:06:23,610
First thing you need to do is select the main CP file that you want to build.

107
00:06:23,650 --> 00:06:27,790
There may be and there will be many, many projects in here.

108
00:06:27,790 --> 00:06:31,960
We'll have project one, Project two, each one of them will have its own main CP.

109
00:06:31,960 --> 00:06:35,710
So we have to be sure that we select the one that we want to build, and then we're going to come up

110
00:06:35,710 --> 00:06:38,710
to terminal and run build task.

111
00:06:38,710 --> 00:06:45,400
You can also do shift command B when we do that, the compiler will build the executable file that we

112
00:06:45,400 --> 00:06:46,090
want to run.

113
00:06:46,090 --> 00:06:47,500
So I'm going to click that now.

114
00:06:48,430 --> 00:06:50,110
And you can see the output right here.

115
00:06:50,140 --> 00:06:52,560
Notice we're using the G plus plus compiler.

116
00:06:52,570 --> 00:06:56,710
There's that minus G minus wall minus standard C plus plus 17.

117
00:06:56,710 --> 00:07:04,480
We entered there's the star CP we entered and it's building main in project one folder.

118
00:07:04,480 --> 00:07:07,530
That's exactly what we want builds finished successfully.

119
00:07:07,540 --> 00:07:14,620
So if you notice a file was created over here, right there, that main file, that is our executable

120
00:07:14,650 --> 00:07:15,010
file.

121
00:07:15,010 --> 00:07:16,240
That's the file we can run.

122
00:07:16,240 --> 00:07:19,630
That's the file that's going to say hello from Project one when we execute it.

123
00:07:19,630 --> 00:07:20,600
How do you execute it?

124
00:07:20,620 --> 00:07:21,280
Real simple.

125
00:07:21,280 --> 00:07:25,720
I'm just going to close this here to give me a little bit more room and I am going to right click on

126
00:07:25,720 --> 00:07:29,470
that and then say Open an integrated terminal.

127
00:07:30,740 --> 00:07:32,990
And it's just opened that folder for me.

128
00:07:32,990 --> 00:07:36,770
And if I type LLS, it'll give me a listing of the files in that folder.

129
00:07:36,770 --> 00:07:42,290
And you can see you can see Main, you can see Main CP and you also see this main symbol file.

130
00:07:42,290 --> 00:07:44,450
That's something that the compiler generates.

131
00:07:44,450 --> 00:07:47,630
So if we want to run this program, we need to run main.

132
00:07:47,630 --> 00:07:50,630
We do a dot slash main.

133
00:07:50,630 --> 00:07:52,460
That dot slash is really important.

134
00:07:52,820 --> 00:07:56,330
So always use dot forward slash and then the name of the executable.

135
00:07:56,330 --> 00:07:59,300
And when I press enter, we should see hello from Project one.

136
00:07:59,600 --> 00:08:00,440
And there it is.

137
00:08:00,440 --> 00:08:02,090
That's exactly what we expected.

138
00:08:02,570 --> 00:08:03,230
Pretty cool.

139
00:08:03,230 --> 00:08:03,980
Pretty easy.

140
00:08:03,980 --> 00:08:08,390
Now, suppose I want to create another project right under here.

141
00:08:08,390 --> 00:08:13,520
If I click on that folder icon right there to create a new folder, it won't do what I want.

142
00:08:13,520 --> 00:08:16,940
What it'll do is it'll create that new folder underneath Project one.

143
00:08:16,940 --> 00:08:18,230
That's not what I want.

144
00:08:18,260 --> 00:08:21,620
I want Project two to be at the same level as Project one.

145
00:08:21,980 --> 00:08:24,380
Intuition says, Come on up here and click it, right?

146
00:08:24,380 --> 00:08:25,850
But that doesn't really work.

147
00:08:25,970 --> 00:08:27,410
So it's not too intuitive.

148
00:08:27,410 --> 00:08:31,550
But the way that you do it is you can select Project one and then just hit escape.

149
00:08:31,850 --> 00:08:35,090
So you see, I just press the escape key and I got this blue box.

150
00:08:35,360 --> 00:08:41,419
Now I can click on that folder and create a new project called Project two, and it's going to be at

151
00:08:41,419 --> 00:08:43,250
the same level as Project one.

152
00:08:43,250 --> 00:08:46,220
Now I can create my main CP file in here.

153
00:08:47,420 --> 00:08:49,870
And I can write another program and I'm actually not going to write it.

154
00:08:49,880 --> 00:08:52,520
I'm just going to copy this program since it's almost the same.

155
00:08:52,640 --> 00:08:59,630
So I'm just going to copy this program from here right into here, and we'll just make one change.

156
00:08:59,630 --> 00:09:00,920
We'll say project two.

157
00:09:02,090 --> 00:09:03,080
That's pretty easy.

158
00:09:03,110 --> 00:09:06,650
Now, if we run this, remember we have to build it first.

159
00:09:06,650 --> 00:09:10,550
We have to select which one we want to build, what we want to build project to.

160
00:09:10,550 --> 00:09:13,100
So make sure you select the main in project two.

161
00:09:13,130 --> 00:09:15,200
We don't want to select the main and Project one.

162
00:09:15,200 --> 00:09:16,370
We've already done that one.

163
00:09:16,670 --> 00:09:19,670
So I'm going to select that and then I'm going to build.

164
00:09:19,670 --> 00:09:25,640
So I'm going to go to terminal and select run the build task and we're done.

165
00:09:25,640 --> 00:09:27,500
You can see Build finished successfully.

166
00:09:27,500 --> 00:09:32,030
Project Two's main was created and there it is right here.

167
00:09:32,030 --> 00:09:35,900
So if I want to execute that, I can just open in the integrated terminal.

168
00:09:36,320 --> 00:09:38,450
We can do ls again if we want.

169
00:09:38,450 --> 00:09:39,170
There it is.

170
00:09:39,170 --> 00:09:43,400
And we do dot slash main and it's going to say hello from Project two.

171
00:09:43,670 --> 00:09:44,600
Pretty easy.

172
00:09:44,690 --> 00:09:47,930
We can modify this program slightly to get input from the user.

173
00:09:47,930 --> 00:09:48,770
Let's do that.

174
00:09:48,770 --> 00:09:55,340
Let's say we have an integer and we'll call that integer favorite number just like that.

175
00:09:55,430 --> 00:09:56,300
And then we'll keep this.

176
00:09:56,300 --> 00:09:57,500
Hello from Project two in there.

177
00:09:57,500 --> 00:09:59,960
But let's also ask the user to enter their favorite number.

178
00:09:59,960 --> 00:10:02,900
So we're going to say enter your favorite number.

179
00:10:03,710 --> 00:10:07,880
Then we're going to read that number into the favorite number variable.

180
00:10:07,880 --> 00:10:11,990
And now we're going to display and now we're going to display.

181
00:10:12,170 --> 00:10:14,630
Your favorite number is the number that just enter

182
00:10:18,080 --> 00:10:19,880
and we'll add a new line at the end.

183
00:10:20,450 --> 00:10:20,960
That's it.

184
00:10:20,960 --> 00:10:23,330
So we've just modified that program slightly.

185
00:10:23,330 --> 00:10:29,270
If we execute Main now, the old program is going to run because we haven't built the new one yet.

186
00:10:29,780 --> 00:10:30,000
Right.

187
00:10:30,050 --> 00:10:33,020
These updates are not in this main executable yet.

188
00:10:33,020 --> 00:10:34,280
That's why we need to build it.

189
00:10:34,280 --> 00:10:39,320
So we're going to select our main CPP and I'm going to select Terminal.

190
00:10:40,220 --> 00:10:41,510
Run the bill task.

191
00:10:41,510 --> 00:10:43,290
We have a successful build.

192
00:10:43,310 --> 00:10:48,410
Now I can come over here to my main right, click on it, open it in the terminal, and we could just

193
00:10:48,410 --> 00:10:49,010
run it.

194
00:10:50,690 --> 00:10:51,970
Hello from project two.

195
00:10:51,980 --> 00:10:53,080
Now it's asking me entry.

196
00:10:53,090 --> 00:10:53,870
My favorite number.

197
00:10:53,870 --> 00:10:55,940
Well, my favorite number let's say is 34.

198
00:10:56,120 --> 00:10:57,050
I'll hit enter.

199
00:10:57,290 --> 00:10:59,330
It says your favorite number is 34.

200
00:11:00,050 --> 00:11:03,770
Simple as that we can create as many projects as we like.

201
00:11:03,770 --> 00:11:10,580
Once our tasks, JSON and our CP properties JSON files are configured, then we can create as many as

202
00:11:10,580 --> 00:11:10,880
we want.

203
00:11:10,880 --> 00:11:12,620
We don't have to touch those again.

204
00:11:12,620 --> 00:11:14,990
They'll apply to all the subprojects.

205
00:11:15,170 --> 00:11:20,960
So in the next video, I'll show you how to use the debugger and how to configure the debugger so that

206
00:11:20,960 --> 00:11:26,660
we can walk through our code one line at a time and inspect our variables and their values as we execute

207
00:11:26,660 --> 00:11:27,320
the code.

208
00:11:27,320 --> 00:11:31,460
It's a very, very handy tool that we can use to help us program.

209
00:11:31,550 --> 00:11:32,870
I'll see you in the next video.

