1 00:00:00,000 --> 00:00:02,334 (light music) 2 00:00:02,334 --> 00:00:05,220 (keyboard clacks) 3 00:00:05,220 --> 00:00:06,053 Frank: In this video, 4 00:00:06,053 --> 00:00:08,039 I'll show you how to use the source code provided 5 00:00:08,039 --> 00:00:11,580 for the course with Visual Studio Code. 6 00:00:11,580 --> 00:00:14,100 First thing we need to do is get to the source code. 7 00:00:14,100 --> 00:00:16,890 The source code is provided in the course content, 8 00:00:16,890 --> 00:00:19,350 and you can see right now, it's in Section 22. 9 00:00:19,350 --> 00:00:21,930 It's in a section called, "Extra Information, 10 00:00:21,930 --> 00:00:23,730 Source code and other stuff." 11 00:00:23,730 --> 00:00:24,600 And if you open that up, 12 00:00:24,600 --> 00:00:26,850 you'll see that "Source Code for all Sections," 13 00:00:26,850 --> 00:00:29,070 and it'll bring you this page right here. 14 00:00:29,070 --> 00:00:31,440 Don't go off of Section 22. 15 00:00:31,440 --> 00:00:34,140 If I add new sections to the course, 16 00:00:34,140 --> 00:00:36,510 that will get bumped down to 23, 24, 25. 17 00:00:36,510 --> 00:00:39,120 So I'm not sure where that will be when you watch the video, 18 00:00:39,120 --> 00:00:40,800 just look for, "Extra Information, 19 00:00:40,800 --> 00:00:43,080 Source code and other stuff." 20 00:00:43,080 --> 00:00:45,450 Open that up and you'll find the source code. 21 00:00:45,450 --> 00:00:46,320 Once you do that, 22 00:00:46,320 --> 00:00:48,240 there will be a link to a zip file 23 00:00:48,240 --> 00:00:51,060 for the source code for each section in the course. 24 00:00:51,060 --> 00:00:52,770 And if you want to download the source code, 25 00:00:52,770 --> 00:00:54,330 just click on the link. 26 00:00:54,330 --> 00:00:57,150 I've already done that and I've downloaded the source code 27 00:00:57,150 --> 00:01:00,300 for Section 4 as a zip file. 28 00:01:00,300 --> 00:01:02,220 And you can see it right here, 29 00:01:02,220 --> 00:01:03,750 there's the zip file right here. 30 00:01:03,750 --> 00:01:07,290 What I'm going to do is I'm just gonna double click on it 31 00:01:07,290 --> 00:01:09,630 and that extracts the Section4 folder. 32 00:01:09,630 --> 00:01:11,520 So I'm just going to select Section4, 33 00:01:11,520 --> 00:01:13,650 and I'm just gonna move it over to my Desktop. 34 00:01:13,650 --> 00:01:15,840 I'm just using the Desktop as an example, 35 00:01:15,840 --> 00:01:18,060 you can move that to any folder you wish. 36 00:01:18,060 --> 00:01:20,430 What's really important is whatever folders you create, 37 00:01:20,430 --> 00:01:23,010 whatever names you use, remember, no spaces, 38 00:01:23,010 --> 00:01:26,100 no international characters, and no special characters. 39 00:01:26,100 --> 00:01:28,080 Otherwise, you may have build problems. 40 00:01:28,080 --> 00:01:30,360 So now once we've got that on our Desktop, 41 00:01:30,360 --> 00:01:32,340 you can see our previous SectionX course 42 00:01:32,340 --> 00:01:34,350 that I created in the previous videos. 43 00:01:34,350 --> 00:01:36,270 There's Section4, what we need to do now is we need 44 00:01:36,270 --> 00:01:40,230 to open up this folder within Visual Studio Code. 45 00:01:40,230 --> 00:01:42,206 You see, this folder has projects within it. 46 00:01:42,206 --> 00:01:44,045 ChallengeSolution, CompilerErrors, 47 00:01:44,045 --> 00:01:45,780 CompilerWarnings, and so forth. 48 00:01:45,780 --> 00:01:47,850 Those will be the individual projects 49 00:01:47,850 --> 00:01:50,460 that we'll also be using within Visual Studio Code. 50 00:01:50,460 --> 00:01:52,140 So I'm just going to close this 51 00:01:52,140 --> 00:01:54,870 and I'm gonna head over to Visual Studio Code right here 52 00:01:54,870 --> 00:01:58,803 and I'm going to open Section4 from my Desktop. 53 00:02:00,120 --> 00:02:02,850 Make sure you open the Section4 folder, 54 00:02:02,850 --> 00:02:05,520 not the folders within Section4. 55 00:02:05,520 --> 00:02:08,280 So I'll select Open and there we go. 56 00:02:08,280 --> 00:02:10,889 You can see that the folder structure has now been opened 57 00:02:10,889 --> 00:02:12,600 within Visual Studio Code. 58 00:02:12,600 --> 00:02:13,920 And we just make this a little bigger. 59 00:02:13,920 --> 00:02:16,290 So you can see that Section4 right there, 60 00:02:16,290 --> 00:02:17,730 and within Section4, 61 00:02:17,730 --> 00:02:19,410 you've got the projects that I mentioned. 62 00:02:19,410 --> 00:02:20,550 We also have some other files. 63 00:02:20,550 --> 00:02:22,920 We have this .codelite folder 64 00:02:22,920 --> 00:02:26,190 and this Makefile and Section4.workspace and so forth. 65 00:02:26,190 --> 00:02:29,850 Those are all CodeLite files, don't worry about those. 66 00:02:29,850 --> 00:02:31,380 You can remove them if you like 67 00:02:31,380 --> 00:02:32,460 or you can just leave them in 68 00:02:32,460 --> 00:02:34,950 and you can use your project with Visual Studio Code 69 00:02:34,950 --> 00:02:35,910 or with CodeLite. 70 00:02:35,910 --> 00:02:39,150 Visual Studio Code will just ignore those files. 71 00:02:39,150 --> 00:02:40,410 Okay, so what do we do next? 72 00:02:40,410 --> 00:02:44,220 Well, we need to configure Visual Studio Code 73 00:02:44,220 --> 00:02:47,790 to think of this section as a C++ section, right? 74 00:02:47,790 --> 00:02:50,490 So what we need to do is we need to set up IntelliSense, 75 00:02:50,490 --> 00:02:53,010 we need to set up our default build task, 76 00:02:53,010 --> 00:02:54,600 and if we want to debug, 77 00:02:54,600 --> 00:02:57,570 we need to set up our launch.json file. 78 00:02:57,570 --> 00:02:59,070 There's a couple of ways we can do that. 79 00:02:59,070 --> 00:03:00,750 We can do it manually just like we did 80 00:03:00,750 --> 00:03:02,610 in the previous videos for this section, 81 00:03:02,610 --> 00:03:03,750 and that's what I'll do here again, 82 00:03:03,750 --> 00:03:05,190 just so you see it one more time. 83 00:03:05,190 --> 00:03:08,220 Or you can grab that .vscode folder 84 00:03:08,220 --> 00:03:10,530 that you've already created in those other projects 85 00:03:10,530 --> 00:03:11,490 and just move it into here. 86 00:03:11,490 --> 00:03:15,120 Just copy it right into Section4 and you'll be good to go. 87 00:03:15,120 --> 00:03:16,680 But I'm gonna do it one step at a time. 88 00:03:16,680 --> 00:03:17,643 So let's do that. 89 00:03:18,480 --> 00:03:20,610 So the first thing we'll do is we'll open up any one 90 00:03:20,610 --> 00:03:22,170 of these and I'm just going to open up, 91 00:03:22,170 --> 00:03:24,330 let's say FirstProgram 92 00:03:24,330 --> 00:03:26,820 and select the main.cpp file within it. 93 00:03:26,820 --> 00:03:28,740 That's the program we'll use to configure. 94 00:03:28,740 --> 00:03:31,860 So what we'll do first is we'll go over here to View 95 00:03:31,860 --> 00:03:35,400 and the Command Pallete and we'll type C++. 96 00:03:35,400 --> 00:03:36,233 And again we're looking 97 00:03:36,233 --> 00:03:39,480 for C/C++ Edit Configurations UI right there. 98 00:03:39,480 --> 00:03:41,040 We'll select that, 99 00:03:41,040 --> 00:03:42,960 and then we wanna be sure we're using g++. 100 00:03:42,960 --> 00:03:46,140 So you come down to Compiler path, and whatever's there, 101 00:03:46,140 --> 00:03:49,143 just change it to g++, we've got that. 102 00:03:49,143 --> 00:03:51,720 Then we'll scroll down a little bit further 103 00:03:51,720 --> 00:03:56,550 and look for the C++17 standard and we'll use c++17. 104 00:03:56,550 --> 00:03:59,730 That's it, I'm going to Command + S to save it 105 00:03:59,730 --> 00:04:01,020 and I'll close that up. 106 00:04:01,020 --> 00:04:03,780 So notice now our .vscode folder has been set up 107 00:04:03,780 --> 00:04:06,600 with our cpp_properties JSON file. 108 00:04:06,600 --> 00:04:08,010 So we're good to go here. 109 00:04:08,010 --> 00:04:10,350 Now what we're going to do is set up the default build task. 110 00:04:10,350 --> 00:04:13,290 So again, click on that main.cpp. 111 00:04:13,290 --> 00:04:16,320 This time, you go up to Terminal and down at the bottom, 112 00:04:16,320 --> 00:04:20,459 Configure Default Build Task, I'll select that. 113 00:04:20,459 --> 00:04:24,030 I'm going to use g++, so I'll select g++. 114 00:04:24,030 --> 00:04:25,650 And this is the file we're gonna make a couple 115 00:04:25,650 --> 00:04:29,040 of changes in, in the args section here on line eight. 116 00:04:29,040 --> 00:04:33,000 We're going to add dash W-A-L-L with W 117 00:04:33,000 --> 00:04:35,190 as capitalized and we're going 118 00:04:35,190 --> 00:04:40,170 to add -std = c++17 119 00:04:40,170 --> 00:04:44,460 to tell the compiler to use the C++ standard just like that. 120 00:04:44,460 --> 00:04:45,630 If you're typing anything, 121 00:04:45,630 --> 00:04:48,300 and you see squiggles like you're seeing right there. 122 00:04:48,300 --> 00:04:50,160 That means there's a typo somewhere. 123 00:04:50,160 --> 00:04:52,170 You might've forgotten a quote mark or a comma. 124 00:04:52,170 --> 00:04:54,060 In this case, it's the comma. 125 00:04:54,060 --> 00:04:57,124 Then what we'll do is we'll take this fileDirname 126 00:04:57,124 --> 00:05:00,810 and we will copy that right into line 12 127 00:05:00,810 --> 00:05:03,270 and replace file with fileDirname. 128 00:05:03,270 --> 00:05:04,110 And once we do that, 129 00:05:04,110 --> 00:05:08,160 we have to add our /*.cpp to tell the compiler 130 00:05:08,160 --> 00:05:10,650 to compile all the files in there. 131 00:05:10,650 --> 00:05:12,270 That's it, so now we're done with that. 132 00:05:12,270 --> 00:05:14,790 We can now build our project. Let's try it out. 133 00:05:14,790 --> 00:05:16,110 So I'm gonna close this out 134 00:05:16,110 --> 00:05:19,050 and I'm gonna open my main.cpp again. 135 00:05:19,050 --> 00:05:20,460 Now once I'm here, 136 00:05:20,460 --> 00:05:24,300 I can come up to Terminal and run the build task 137 00:05:24,300 --> 00:05:26,150 or you can press Shift + Command + B. 138 00:05:27,030 --> 00:05:27,960 You can see down here, 139 00:05:27,960 --> 00:05:30,360 we've got a build and it was successful. 140 00:05:30,360 --> 00:05:31,320 Always double check. 141 00:05:31,320 --> 00:05:33,600 You've got your -g, your -Wall, 142 00:05:33,600 --> 00:05:36,240 you've got your standard c++17, 143 00:05:36,240 --> 00:05:39,120 and we've got our CPP files being compiled. 144 00:05:39,120 --> 00:05:42,030 At that point, now we have this main executable 145 00:05:42,030 --> 00:05:45,390 that was created for us right here inside project one. 146 00:05:45,390 --> 00:05:46,980 So I can right click on that 147 00:05:46,980 --> 00:05:49,350 and open it in the integrated terminal. 148 00:05:49,350 --> 00:05:52,470 We can do an ls to see the files that we've got, 149 00:05:52,470 --> 00:05:53,700 and we've got several files. 150 00:05:53,700 --> 00:05:55,110 Some of them are CodeLite files. 151 00:05:55,110 --> 00:05:58,290 Don't worry about them, this .mk and the .project file. 152 00:05:58,290 --> 00:06:00,120 But we do have our main executable right here. 153 00:06:00,120 --> 00:06:05,120 If we wanna run it, we just type ./main and press Enter. 154 00:06:05,617 --> 00:06:07,800 "Enter your favorite number between one and 100." 155 00:06:07,800 --> 00:06:11,550 Let's say 45. "Amazing, that's my favorite number too." 156 00:06:11,550 --> 00:06:13,920 And you can see from the source code up here, 157 00:06:13,920 --> 00:06:15,750 that's exactly what the program's doing. 158 00:06:15,750 --> 00:06:18,870 So that's it for configuring for the build. 159 00:06:18,870 --> 00:06:21,390 Now in order to configure for debugging, 160 00:06:21,390 --> 00:06:24,150 let me close this window here to make up a little more room. 161 00:06:24,150 --> 00:06:25,170 What we can do is again, 162 00:06:25,170 --> 00:06:29,790 we can select our main.cpp file and we can come up to Run, 163 00:06:29,790 --> 00:06:32,130 Add Configuration, and select C++, 164 00:06:32,130 --> 00:06:36,750 GDB, LLDB, and g++. 165 00:06:36,750 --> 00:06:37,650 Now at this point, 166 00:06:37,650 --> 00:06:39,450 we'll want to kill the debugger right here, 167 00:06:39,450 --> 00:06:42,120 we want to use that little red square right here icon 168 00:06:42,120 --> 00:06:43,050 to stop it. 169 00:06:43,050 --> 00:06:44,370 And what we want to do is we want 170 00:06:44,370 --> 00:06:48,570 to edit this launch.json file that was created right there, 171 00:06:48,570 --> 00:06:49,950 which is open already. 172 00:06:49,950 --> 00:06:51,480 The only thing we want to do here is we want 173 00:06:51,480 --> 00:06:54,448 to change the type to LLDB. 174 00:06:54,448 --> 00:06:55,860 (keyboard taps) 175 00:06:55,860 --> 00:06:57,360 When we do that, 176 00:06:57,360 --> 00:06:59,460 you'll notice we have some errors just like we had before. 177 00:06:59,460 --> 00:07:02,730 In the previous videos, we just want to delete those lines. 178 00:07:02,730 --> 00:07:03,930 We don't want any squiggles 179 00:07:03,930 --> 00:07:06,510 or any red markers or anything anywhere. 180 00:07:06,510 --> 00:07:08,310 That's it, your current working directory 181 00:07:08,310 --> 00:07:10,890 should be fileDirname, make sure that that's correct. 182 00:07:10,890 --> 00:07:12,900 If it's not, you can change it to that. 183 00:07:12,900 --> 00:07:16,350 And that's it, I'll save that and we'll close this up. 184 00:07:16,350 --> 00:07:18,480 And now we can debug this program that's open. 185 00:07:18,480 --> 00:07:20,520 So I can click on the program, 186 00:07:20,520 --> 00:07:23,850 and then select the debugger right over here on the left, 187 00:07:23,850 --> 00:07:26,160 that bug, play icon, run and debug, 188 00:07:26,160 --> 00:07:28,650 I can select that and it's waiting for us now 189 00:07:28,650 --> 00:07:32,550 to execute it by clicking on that green arrow up here. 190 00:07:32,550 --> 00:07:33,990 I do wanna put a break point in. 191 00:07:33,990 --> 00:07:36,960 So let's put a break point right here on line seven. 192 00:07:36,960 --> 00:07:39,690 You can come across here, you'll see that red dot. 193 00:07:39,690 --> 00:07:41,730 There's a break point showing up down here. 194 00:07:41,730 --> 00:07:44,490 If you see a lot of other break points from other projects, 195 00:07:44,490 --> 00:07:45,600 clear them out. 196 00:07:45,600 --> 00:07:46,560 And then just come in here 197 00:07:46,560 --> 00:07:48,450 and select the break point you want. 198 00:07:48,450 --> 00:07:49,590 At this point, we can run it. 199 00:07:49,590 --> 00:07:51,900 So we'll just click on that red arrow. 200 00:07:51,900 --> 00:07:55,770 The debugger will engage, this bottom bar turns orange. 201 00:07:55,770 --> 00:07:58,380 You can see favorite_number up here, set to zero. 202 00:07:58,380 --> 00:07:59,580 We never initialized it 203 00:07:59,580 --> 00:08:01,350 and we'll talk about that in the class. 204 00:08:01,350 --> 00:08:03,990 Our current executing line is line seven. 205 00:08:03,990 --> 00:08:06,210 So we can execute it by just stepping over 206 00:08:06,210 --> 00:08:08,340 by pressing this icon right here. 207 00:08:08,340 --> 00:08:09,870 And the output will be here in terminal. 208 00:08:09,870 --> 00:08:11,340 So you could always click there. 209 00:08:11,340 --> 00:08:13,260 So I'll do that and I'll do it one more time. 210 00:08:13,260 --> 00:08:15,450 It's asking me now for the favorite number. 211 00:08:15,450 --> 00:08:17,490 Again, I'll type 45 one more time. 212 00:08:17,490 --> 00:08:18,510 And when I press Enter, 213 00:08:18,510 --> 00:08:20,880 now you'll see that I'm stopped at line nine 214 00:08:20,880 --> 00:08:23,760 and favorite_number's value has changed to 45. 215 00:08:23,760 --> 00:08:25,500 And as before, we can, you know, 216 00:08:25,500 --> 00:08:29,010 hover over that variable name and we can see our value. 217 00:08:29,010 --> 00:08:29,880 To finish the program, 218 00:08:29,880 --> 00:08:31,440 you can click the play arrow 219 00:08:31,440 --> 00:08:33,750 or you could just stop it right here in the debugger. 220 00:08:33,750 --> 00:08:36,690 I'll just continue. That's it, so there you go. 221 00:08:36,690 --> 00:08:40,320 This video shows you how to set up the source code provided 222 00:08:40,320 --> 00:08:42,840 for the course to work within Visual Studio Code. 223 00:08:42,840 --> 00:08:47,043 So now we can edit, we can debug, and we can build and run.