1 00:00:00,000 --> 00:00:02,667 (upbeat music) 2 00:00:05,130 --> 00:00:07,020 Frank: Hello everyone. 3 00:00:07,020 --> 00:00:10,230 In this video what we'll do is we'll download and extract 4 00:00:10,230 --> 00:00:13,290 the source code provided in the course, 5 00:00:13,290 --> 00:00:14,820 and we'll set it up so that we can use it 6 00:00:14,820 --> 00:00:16,920 with Visual Studio Code. 7 00:00:16,920 --> 00:00:19,110 The source code is located 8 00:00:19,110 --> 00:00:21,000 in one of the last sections of the course, 9 00:00:21,000 --> 00:00:23,370 right now it's in section 22, 10 00:00:23,370 --> 00:00:25,980 but that could change as I add content to the course, 11 00:00:25,980 --> 00:00:29,700 that probably becomes section 23 and then 24 and so forth. 12 00:00:29,700 --> 00:00:31,110 So the best thing is to search 13 00:00:31,110 --> 00:00:32,430 for a section named 14 00:00:32,430 --> 00:00:35,610 Extra Information, Source Code, and Other Stuff. 15 00:00:35,610 --> 00:00:38,100 And in there there will be a video, 16 00:00:38,100 --> 00:00:40,170 Source Code for All Sections. 17 00:00:40,170 --> 00:00:42,720 And when you select that, this is what you're going to get. 18 00:00:42,720 --> 00:00:44,321 It's a bunch of links to zip files 19 00:00:44,321 --> 00:00:48,420 that contain the source code for the course projects. 20 00:00:48,420 --> 00:00:49,590 So what you wanna do is, 21 00:00:49,590 --> 00:00:51,810 depending on which section of the course you're in, 22 00:00:51,810 --> 00:00:54,450 you want to download the zip file for that section. 23 00:00:54,450 --> 00:00:55,283 So in this case, 24 00:00:55,283 --> 00:00:57,720 I'm going to download the source code for section four 25 00:00:57,720 --> 00:00:59,940 and I'm just going to click on there, 26 00:00:59,940 --> 00:01:01,345 and that will download a zip file, 27 00:01:01,345 --> 00:01:03,473 which I'm just going to save. 28 00:01:03,473 --> 00:01:07,170 Now that I've saved it, I'm going to go to my downloads 29 00:01:07,170 --> 00:01:08,520 and I'm just gonna extract it. 30 00:01:08,520 --> 00:01:12,513 So I'm just gonna Right Click and extract right here. 31 00:01:14,250 --> 00:01:15,870 All right, so this is what we've got now, 32 00:01:15,870 --> 00:01:18,870 you can see it's extracted it to a section four folder, 33 00:01:18,870 --> 00:01:21,600 and inside that section four folder are all the projects. 34 00:01:21,600 --> 00:01:22,470 So what I want to do 35 00:01:22,470 --> 00:01:25,070 is I want you to just copy this section four folder, 36 00:01:26,430 --> 00:01:29,550 or you can cut it if you like, to the desktop, 37 00:01:29,550 --> 00:01:31,600 just so I can show you how to do it here. 38 00:01:32,864 --> 00:01:36,390 So now I've just downloaded and extracted 39 00:01:36,390 --> 00:01:37,920 all the projects in that section, 40 00:01:37,920 --> 00:01:39,540 into this section four folder. 41 00:01:39,540 --> 00:01:41,130 So I think you know what to do now. 42 00:01:41,130 --> 00:01:42,120 What we want to do is we want 43 00:01:42,120 --> 00:01:45,930 to open up this section four folder in Visual Studio Code 44 00:01:45,930 --> 00:01:48,447 and then set up IntelliSense, the tasks JSON 45 00:01:48,447 --> 00:01:51,510 and the launch JSON again, so let's do that. 46 00:01:51,510 --> 00:01:54,120 I'm gonna close all this up 'cause I don't need it anymore. 47 00:01:54,120 --> 00:01:56,430 And what I want to do now is I wanna open a folder. 48 00:01:56,430 --> 00:01:58,230 So again, we'll open folder, 49 00:01:58,230 --> 00:02:00,270 and I'm going to go to my desktop 50 00:02:00,270 --> 00:02:04,020 and I wanna open section four, that's the one I want. 51 00:02:04,020 --> 00:02:05,643 So I'm just gonna click OK. 52 00:02:06,480 --> 00:02:08,009 And now you'll see that section four 53 00:02:08,009 --> 00:02:10,380 was opened up in Visual Studio Code, 54 00:02:10,380 --> 00:02:12,120 which is exactly what we want. 55 00:02:12,120 --> 00:02:14,010 You'll also notice that there are some folders 56 00:02:14,010 --> 00:02:16,710 like codelite and MakeFile and things like that. 57 00:02:16,710 --> 00:02:17,640 Don't worry about those. 58 00:02:17,640 --> 00:02:20,160 Those are things that CodeLite needs, 59 00:02:20,160 --> 00:02:22,170 Visual Studio will just ignore them. 60 00:02:22,170 --> 00:02:24,990 But we need to configure this to work with Visual Studio. 61 00:02:24,990 --> 00:02:26,308 So we have to go through the same process 62 00:02:26,308 --> 00:02:28,260 that we did before. 63 00:02:28,260 --> 00:02:31,830 We have to do it once per major section. 64 00:02:31,830 --> 00:02:32,700 A couple ways to do this, 65 00:02:32,700 --> 00:02:34,470 we could do it manually like we did before, 66 00:02:34,470 --> 00:02:35,880 which is what I'm going to do here, 67 00:02:35,880 --> 00:02:37,680 just so you can see it one more time. 68 00:02:37,680 --> 00:02:40,500 Or you could copy your VS Code folder 69 00:02:40,500 --> 00:02:43,380 from an existing project into this project. 70 00:02:43,380 --> 00:02:45,720 Okay, so let's just do it manually. 71 00:02:45,720 --> 00:02:49,470 First thing we want to do is I wanna close this get started 72 00:02:49,470 --> 00:02:51,352 and I wanna click on any of the, 73 00:02:51,352 --> 00:02:52,950 let's see this guy right here, 74 00:02:52,950 --> 00:02:55,290 any of the main.cpp files in there, 75 00:02:55,290 --> 00:02:58,170 any C++ source file is what we need. 76 00:02:58,170 --> 00:03:01,710 And then we're gonna go to view, command palette, 77 00:03:01,710 --> 00:03:03,750 and type in again, C++, 78 00:03:03,750 --> 00:03:06,423 until we see edit configurations UI. 79 00:03:07,260 --> 00:03:09,450 We're gonna set up the IntelliSense again. 80 00:03:09,450 --> 00:03:13,770 We'll scroll down and make sure that we've got, 81 00:03:13,770 --> 00:03:15,690 so we'll scroll right here to compiler path 82 00:03:15,690 --> 00:03:20,100 and we want to be sure that we are using g++, right there. 83 00:03:20,100 --> 00:03:22,620 And then we're gonna scroll down a little bit more 84 00:03:22,620 --> 00:03:26,613 to the C++ standard and we're going to choose c++17. 85 00:03:28,110 --> 00:03:30,810 That's it. I'm gonna CTRL + S to save 86 00:03:30,810 --> 00:03:34,320 and I'm done with that, perfect. 87 00:03:34,320 --> 00:03:37,020 Now you notice we've got our VS Code folder here 88 00:03:37,020 --> 00:03:39,540 and our CPP properties are set up. 89 00:03:39,540 --> 00:03:41,700 So again, I'm gonna select main.cpp, 90 00:03:41,700 --> 00:03:44,040 and I'm gonna come up to terminal, 91 00:03:44,040 --> 00:03:46,533 and configure the default build task. 92 00:03:47,550 --> 00:03:50,023 I'm going to select g++. 93 00:03:51,900 --> 00:03:53,010 And now once I'm here, 94 00:03:53,010 --> 00:03:54,960 I'm gonna make those same changes we made before, 95 00:03:54,960 --> 00:03:56,970 we're gonna enable all warnings. 96 00:03:56,970 --> 00:03:58,773 So -wall. 97 00:03:59,700 --> 00:04:03,093 We are going to enable the c++17 standard, 98 00:04:04,680 --> 00:04:07,680 and we're going to change the file on line 12 99 00:04:07,680 --> 00:04:09,013 to fileDirname. 100 00:04:12,475 --> 00:04:17,160 I'm going to copy this and I'm gonna paste it right in here. 101 00:04:17,160 --> 00:04:22,160 And then finally we're going to add the /*.cpp, 102 00:04:22,650 --> 00:04:24,810 so that will compile all the files. 103 00:04:24,810 --> 00:04:26,040 Now when we do these, 104 00:04:26,040 --> 00:04:27,810 you'll notice is sometimes you'll see squigglies. 105 00:04:27,810 --> 00:04:29,499 So for example, if I get rid of that comma, 106 00:04:29,499 --> 00:04:32,160 you'll see some squigglies show up, right? 107 00:04:32,160 --> 00:04:34,290 We don't want any of them, those are errors. 108 00:04:34,290 --> 00:04:36,450 And we just wanna be sure that everything looks clean. 109 00:04:36,450 --> 00:04:37,650 If something doesn't look clean, 110 00:04:37,650 --> 00:04:38,850 look at the video and make sure 111 00:04:38,850 --> 00:04:41,130 that you haven't missed any quote marks or commas 112 00:04:41,130 --> 00:04:42,180 and so forth. 113 00:04:42,180 --> 00:04:45,030 So that's it, I'm going to save this 114 00:04:45,030 --> 00:04:47,430 and I'm gonna close this up. 115 00:04:47,430 --> 00:04:51,259 Now what we'll do is we'll select main.cpp on FirstProgram, 116 00:04:51,259 --> 00:04:52,950 and you can see what the FirstProgram is doing. 117 00:04:52,950 --> 00:04:55,470 It's similar to what we did before with the favorite number, 118 00:04:55,470 --> 00:04:57,150 what I want to do now is just test it out. 119 00:04:57,150 --> 00:05:01,020 So I'm gonna select that and I'm gonna go to terminal, 120 00:05:01,020 --> 00:05:02,160 and run the build task. 121 00:05:02,160 --> 00:05:04,710 So that will build our project, 122 00:05:04,710 --> 00:05:07,260 and you'll see build finished successfully. 123 00:05:07,260 --> 00:05:11,550 So remember, the main executable was created right here, 124 00:05:11,550 --> 00:05:13,200 right inside that project. 125 00:05:13,200 --> 00:05:16,950 So I'm gonna right Click On it, open an integrated terminal, 126 00:05:16,950 --> 00:05:19,353 and then I'm gonna type ./main. 127 00:05:20,490 --> 00:05:21,960 What's my favorite number? 128 00:05:21,960 --> 00:05:24,300 Let's say it's 34 this time. 129 00:05:24,300 --> 00:05:25,950 Amazing, that's my favorite number too. 130 00:05:25,950 --> 00:05:28,770 That's exactly what we're supposed to get. 131 00:05:28,770 --> 00:05:32,253 Okay, perfect, so now let's say I wanted to run Project1. 132 00:05:34,170 --> 00:05:36,690 I can go to main.cpp there, 133 00:05:36,690 --> 00:05:40,440 and again I can come up to terminal, run build task. 134 00:05:40,440 --> 00:05:42,521 Now it's going to build Project1. 135 00:05:42,521 --> 00:05:44,670 And you could see from the message right here, 136 00:05:44,670 --> 00:05:47,370 you could see Project1 is being built right there. 137 00:05:47,370 --> 00:05:49,860 We've created our executable within Project1, 138 00:05:49,860 --> 00:05:53,520 which I can Right Click, open in the integrated terminal. 139 00:05:53,520 --> 00:05:56,220 And you can see Project1 just says Hello Project one. 140 00:05:56,220 --> 00:06:00,270 We can run it again, and now we're running Project1. 141 00:06:00,270 --> 00:06:02,306 So this is a real easy way to organize yourself, 142 00:06:02,306 --> 00:06:04,590 and to get everything running nicely. 143 00:06:04,590 --> 00:06:05,610 We're done with that. 144 00:06:05,610 --> 00:06:08,460 The last step is to get the debugger working. 145 00:06:08,460 --> 00:06:10,140 So what we can do now, again, 146 00:06:10,140 --> 00:06:13,353 select one of the main.cpp files, there's one. 147 00:06:14,220 --> 00:06:17,680 And we come up to run and add configuration 148 00:06:19,380 --> 00:06:24,380 and select c++ GDB/LLDB, and then g++. 149 00:06:27,000 --> 00:06:29,040 We're gonna get some stuff happening, 150 00:06:29,040 --> 00:06:30,660 whatever happens, just let it happen 151 00:06:30,660 --> 00:06:32,373 and then just kill it right here. 152 00:06:33,270 --> 00:06:35,850 So I'll press that little red square. 153 00:06:35,850 --> 00:06:36,683 And now what we want to do 154 00:06:36,683 --> 00:06:39,300 is we want to come back over to our explorer 155 00:06:39,300 --> 00:06:42,090 and we want to edit that launch.json file. 156 00:06:42,090 --> 00:06:44,790 And all we really want to do is change this guy right here, 157 00:06:44,790 --> 00:06:46,470 this current working directory, 158 00:06:46,470 --> 00:06:49,140 I wanna change that to file directory name. 159 00:06:49,140 --> 00:06:51,783 So I'm just going to copy and paste. 160 00:06:54,720 --> 00:06:56,790 That's it, I'll save. 161 00:06:56,790 --> 00:07:00,210 And let's pick FirstProgram again, so right here. 162 00:07:00,210 --> 00:07:02,610 And let's say that this is the one we want to debug. 163 00:07:02,610 --> 00:07:04,680 So what we can do is we can click on the bug, 164 00:07:04,680 --> 00:07:07,350 if there are any break points done here, we can clear them. 165 00:07:07,350 --> 00:07:08,880 We will add our own break point, 166 00:07:08,880 --> 00:07:11,820 let's say we want to add a break point right on line eight, 167 00:07:11,820 --> 00:07:13,770 and then we select that little green play button 168 00:07:13,770 --> 00:07:17,883 right up here and the debugger will engage. 169 00:07:19,410 --> 00:07:22,050 You can see where we're stopped on line eight, 170 00:07:22,050 --> 00:07:23,860 and you can see my favorite number's over here. 171 00:07:23,860 --> 00:07:25,380 Lemme just move over. 172 00:07:25,380 --> 00:07:27,256 Now you'll notice that we're getting 32767. 173 00:07:27,256 --> 00:07:30,210 What in the world is that? I don't see that anywhere. 174 00:07:30,210 --> 00:07:32,670 Well, we haven't initialized favorite number to anything. 175 00:07:32,670 --> 00:07:35,640 So whatever displays here really is undefined, 176 00:07:35,640 --> 00:07:37,110 and I'll talk more about that in the class, 177 00:07:37,110 --> 00:07:39,900 that's really an important issue with C++. 178 00:07:39,900 --> 00:07:42,750 So now we could just step through the program. 179 00:07:42,750 --> 00:07:44,673 Let's step through right here. 180 00:07:45,510 --> 00:07:48,300 Enter your favorite number between one and 100. 181 00:07:48,300 --> 00:07:53,100 So let's say I wanted to enter 56 and press Enter. 182 00:07:53,100 --> 00:07:56,940 Now we're on line nine and I can step over that. 183 00:07:56,940 --> 00:07:59,940 Also, notice my favorite number changed here, 184 00:07:59,940 --> 00:08:03,150 and I can hover over to see that it's 56, 185 00:08:03,150 --> 00:08:06,870 and when we're done we could just finish and that's it. 186 00:08:06,870 --> 00:08:09,120 So that's how we can get the source code 187 00:08:09,120 --> 00:08:12,300 provided for the course to work with Visual Studio Code. 188 00:08:12,300 --> 00:08:14,310 It's really pretty easy once you get the hang of it, 189 00:08:14,310 --> 00:08:16,557 you can set up the tasks JSON and launch JSON files 190 00:08:16,557 --> 00:08:18,210 really quickly. 191 00:08:18,210 --> 00:08:21,150 Or like I said, you could just copy them and paste them 192 00:08:21,150 --> 00:08:23,550 into the new structure that you're creating. 193 00:08:23,550 --> 00:08:25,800 Alright, so that shows you how to set everything up 194 00:08:25,800 --> 00:08:29,103 for Linux Ubuntu, I'll see you in the rest of the course.