1 00:00:05,200 --> 00:00:10,570 In this video, I'll show you how to use the source code provided for the course with Visual Studio 2 00:00:10,570 --> 00:00:11,140 code. 3 00:00:11,470 --> 00:00:13,780 First thing we need to do is get to the source code. 4 00:00:14,050 --> 00:00:19,370 The source code is provided in the course content and you can see right now it's in section 22. 5 00:00:19,390 --> 00:00:23,650 It's in a section called Extra Information Source Code and other stuff. 6 00:00:23,650 --> 00:00:26,860 And if you open that up, you'll see that source code for all sections. 7 00:00:26,860 --> 00:00:28,720 And it will bring you this page right here. 8 00:00:28,960 --> 00:00:31,270 Don't go off of section 22. 9 00:00:31,360 --> 00:00:36,550 If I add new sections to the course, that will get bumped down to 23, 24, 25. 10 00:00:36,550 --> 00:00:38,930 So I'm not sure where that will be when you watch the video. 11 00:00:38,950 --> 00:00:43,030 Just look for extra information, source code and other stuff. 12 00:00:43,060 --> 00:00:44,920 Open that up and you'll find the source code. 13 00:00:45,310 --> 00:00:50,560 Once you do that, there will be a link to a zip file for the source code for each section in the course. 14 00:00:50,950 --> 00:00:53,800 And if you want to download the source code, just click on the link. 15 00:00:54,340 --> 00:01:00,820 I've already done that and I've downloaded the source code for section four as a zip file and you can 16 00:01:00,820 --> 00:01:01,900 see it right here. 17 00:01:02,140 --> 00:01:03,700 There's the zip file right here. 18 00:01:03,770 --> 00:01:06,190 What I'm going to do is I'm just going to double click on it. 19 00:01:07,260 --> 00:01:09,600 And then extracts the Section four folder. 20 00:01:09,660 --> 00:01:13,570 So I'm just going to select Section four and I'm just going to move it over to my desktop. 21 00:01:13,590 --> 00:01:15,900 I'm just using the desktop and an example. 22 00:01:15,900 --> 00:01:17,910 You can move that to any folder you wish. 23 00:01:17,940 --> 00:01:21,750 What's really important is whatever folders you create, whatever names you use. 24 00:01:21,780 --> 00:01:26,120 Remember, no spaces, no international characters and no special characters. 25 00:01:26,130 --> 00:01:27,950 Otherwise, you may have build problems. 26 00:01:27,960 --> 00:01:32,940 So now once we've got that on our desktop, you can see our previous Section X course that I created 27 00:01:32,940 --> 00:01:34,230 in the previous videos. 28 00:01:34,230 --> 00:01:40,120 This section for what we need to do now is we need to open up this folder within Visual Studio code. 29 00:01:40,140 --> 00:01:44,880 You see, this folder has projects within it challenge solution, compiler errors, compiler warnings 30 00:01:44,880 --> 00:01:45,660 and so forth. 31 00:01:45,660 --> 00:01:50,430 Those will be the individual projects that will also be using within Visual Studio code. 32 00:01:50,430 --> 00:01:55,260 So I'm just going to close this and I'm going to head over to Visual Studio code right here, and I'm 33 00:01:55,260 --> 00:01:58,770 going to open Section four from my desktop. 34 00:02:00,050 --> 00:02:05,330 Make sure you open the section four folder, not the folders within section four. 35 00:02:05,360 --> 00:02:08,300 So I'll select open and there we go. 36 00:02:08,300 --> 00:02:13,280 You can see that the folder structure has now been opened within Visual Studio code and it just makes 37 00:02:13,280 --> 00:02:13,940 this a little bigger. 38 00:02:13,940 --> 00:02:18,770 So you can see that Section four right there and within Section four you've got the projects that I 39 00:02:18,770 --> 00:02:19,340 mentioned. 40 00:02:19,340 --> 00:02:20,570 We also have some other files. 41 00:02:20,570 --> 00:02:26,090 We have this dot code light folder and this Makefile in section four workspace and so forth. 42 00:02:26,090 --> 00:02:28,550 Those are all code light files. 43 00:02:28,550 --> 00:02:29,780 Don't worry about those. 44 00:02:29,780 --> 00:02:34,370 You can remove them if you like, or you can just leave them in and you can use your project with Visual 45 00:02:34,370 --> 00:02:35,930 Studio code or with code light. 46 00:02:35,930 --> 00:02:38,450 Visual Studio code will just ignore those files. 47 00:02:39,470 --> 00:02:40,400 So what do we do next? 48 00:02:40,400 --> 00:02:47,540 Well, we need to configure Visual Studio code to think of this section as a C plus plus section. 49 00:02:47,540 --> 00:02:47,810 Right. 50 00:02:47,810 --> 00:02:52,820 So what we need to do is we need to set up IntelliSense, we need to set up our default build task. 51 00:02:52,820 --> 00:02:57,500 And if we want to debug, we need to set up our launch JSON file. 52 00:02:57,500 --> 00:02:59,060 There's a couple of ways we can do that. 53 00:02:59,060 --> 00:03:02,570 We can do it manually, just like we did in the previous videos for this section. 54 00:03:02,570 --> 00:03:07,450 And that's what I'll do here again, just so you see it one more time, or you can grab that dot vs 55 00:03:07,490 --> 00:03:11,510 code folder that you've already created in those other projects and just move it into here. 56 00:03:11,510 --> 00:03:16,370 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 57 00:03:16,370 --> 00:03:17,630 time, so let's do that. 58 00:03:18,420 --> 00:03:21,010 So the first thing we'll do is we'll open up any one of these. 59 00:03:21,010 --> 00:03:26,790 And I'm just going to open up, let's say first program and select the main CPP file within it. 60 00:03:26,790 --> 00:03:28,710 That's the program we'll use to configure. 61 00:03:28,710 --> 00:03:33,060 So what we'll do first is we'll go over here to view and the command palette. 62 00:03:34,110 --> 00:03:35,400 We'll type C++. 63 00:03:35,400 --> 00:03:41,310 And again, we're looking for C, C++, edit configurations UI right there, we'll select that and then 64 00:03:41,310 --> 00:03:42,990 we want to be sure we're using C++. 65 00:03:42,990 --> 00:03:47,460 So you come down to compiler path and whatever's there, just change it to G Plus. 66 00:03:47,460 --> 00:03:49,640 Plus, we've got that note. 67 00:03:49,710 --> 00:03:55,950 We'll scroll down a little bit further and look for the C++ 17 standard and we'll use C++ 17. 68 00:03:56,580 --> 00:03:57,240 That's it. 69 00:03:57,240 --> 00:04:00,900 I'm going to command S to save it and I'll close that up. 70 00:04:00,900 --> 00:04:07,200 So notice now our V code folder has been set up with our CP properties JSON file, so we're good to 71 00:04:07,200 --> 00:04:07,860 go here. 72 00:04:07,860 --> 00:04:10,380 Now what we're going to do is set up the default build test. 73 00:04:10,380 --> 00:04:12,960 So again, click on that main CP. 74 00:04:13,230 --> 00:04:16,320 This time you go up to terminal and down at the bottom. 75 00:04:16,320 --> 00:04:18,360 Configure default, build task. 76 00:04:18,630 --> 00:04:19,680 I'll select that. 77 00:04:20,399 --> 00:04:23,850 I'm going to use G plus plus, I'll select G plus plus. 78 00:04:23,850 --> 00:04:29,040 And this is the file we're going to make a couple of changes in in the ARGs section here on line eight, 79 00:04:29,040 --> 00:04:38,790 we're going to add dash w LX with W is capitalized and we're going to add dash speed equals C plus plus 80 00:04:39,360 --> 00:04:44,370 17 to tell the compiler to use the C++ standard just like that. 81 00:04:44,370 --> 00:04:48,930 If you're typing anything and you see squiggles like you're seeing right there, that means there's 82 00:04:48,930 --> 00:04:52,170 a typo somewhere you might have forgotten a quote mark or a comma. 83 00:04:52,170 --> 00:04:53,460 In this case, it's the comma. 84 00:04:53,940 --> 00:05:01,410 Then what we'll do is we'll take this file your name and we'll copy that right into line 12 and replace 85 00:05:01,410 --> 00:05:03,000 file with file your name. 86 00:05:03,180 --> 00:05:09,930 And once we do that, we have to add our slash start up CP to tell the compiler to compile all the files 87 00:05:09,930 --> 00:05:10,440 in there. 88 00:05:10,590 --> 00:05:11,190 That's it. 89 00:05:11,190 --> 00:05:12,240 So now we're done with that. 90 00:05:12,240 --> 00:05:13,890 We can now build our project. 91 00:05:13,890 --> 00:05:14,730 Let's try it out. 92 00:05:14,730 --> 00:05:18,240 So I'm going to close this out and I'm going to open my main CP again. 93 00:05:18,930 --> 00:05:25,440 Now, once I'm here, I can come up to terminal and run the build task or you can press shift command 94 00:05:25,470 --> 00:05:25,920 b. 95 00:05:27,030 --> 00:05:30,090 You can see down here we've got a build and it was successful. 96 00:05:30,300 --> 00:05:31,310 Always double check. 97 00:05:31,320 --> 00:05:37,860 You've got your minus G, your minus wall, you've got your standard C++ 17 and we've got our CP files 98 00:05:37,860 --> 00:05:40,050 being compiled at that point. 99 00:05:40,050 --> 00:05:45,390 Now we have this main executable that was created for us right here inside Project one. 100 00:05:45,390 --> 00:05:48,900 So I can right click on that and open it in the integrated terminal. 101 00:05:49,290 --> 00:05:53,700 We can do an LZ to see the files that we've got and we've got several files. 102 00:05:53,700 --> 00:05:55,080 Some of them are code light files. 103 00:05:55,080 --> 00:05:55,890 Don't worry about them. 104 00:05:55,890 --> 00:05:56,820 This dot mkay. 105 00:05:56,820 --> 00:05:58,140 And the dot project file. 106 00:05:58,140 --> 00:06:01,050 But we do have our main executable right here if we want to run it. 107 00:06:01,170 --> 00:06:07,830 We just type dot forward slash main and press enter enter your favorite number between one and 100, 108 00:06:07,830 --> 00:06:09,150 let's say 45. 109 00:06:09,510 --> 00:06:10,020 Amazing. 110 00:06:10,020 --> 00:06:11,460 That's my favorite number two. 111 00:06:11,460 --> 00:06:15,660 And you can see from the source code up here, that's exactly what the program is doing. 112 00:06:15,660 --> 00:06:18,750 So that's it for configuring for the build. 113 00:06:18,750 --> 00:06:23,790 Now, in order to configure for debugging, let me close this window here to make up a little more room. 114 00:06:24,000 --> 00:06:31,170 What we can do is again, we can select our main DHCP file and we can come up to run add configuration 115 00:06:31,170 --> 00:06:34,230 and select C++ gdb ltb. 116 00:06:35,160 --> 00:06:36,540 And G plus plus. 117 00:06:36,810 --> 00:06:39,450 Now, at this point, we're want to kill the debugger right here. 118 00:06:39,450 --> 00:06:42,930 We want to use that little red square right here icon to stop it. 119 00:06:42,930 --> 00:06:48,780 And what we want to do is we want to edit this launch JSON file that was created right there, which 120 00:06:48,780 --> 00:06:49,770 is open already. 121 00:06:49,920 --> 00:06:54,630 The only thing we want to do here is we want to change the type to LTB. 122 00:06:55,740 --> 00:07:00,390 When we do that, you'll notice we have some errors just like we had before in the previous videos. 123 00:07:00,390 --> 00:07:02,580 We just want to delete those lines. 124 00:07:02,580 --> 00:07:05,970 We don't want any squiggles or any red markers or anything anywhere. 125 00:07:06,450 --> 00:07:07,050 That's it. 126 00:07:07,050 --> 00:07:09,180 Your current working directory should be filed. 127 00:07:09,180 --> 00:07:09,780 Your name. 128 00:07:09,780 --> 00:07:10,890 Make sure that that's correct. 129 00:07:10,890 --> 00:07:13,650 If it's not, you can change it to that and that's it. 130 00:07:13,650 --> 00:07:15,720 I'll save that and we'll close this up. 131 00:07:16,260 --> 00:07:18,480 And now we can debug this program that's open. 132 00:07:18,480 --> 00:07:24,690 So I can click on the program and then select the debugger right over here on the left, that bug play 133 00:07:24,690 --> 00:07:26,070 icon run and debug. 134 00:07:26,100 --> 00:07:32,130 I can select that and it's waiting for us now to execute it by clicking on that green arrow up here. 135 00:07:32,520 --> 00:07:36,600 I do want to put a breakpoint in, so let's put a breakpoint right here on line seven. 136 00:07:36,960 --> 00:07:39,420 You can come across here, you'll see that red dot. 137 00:07:39,600 --> 00:07:41,700 There's a breakpoint showing up down here. 138 00:07:41,700 --> 00:07:46,560 If you see a lot of other breakpoints from other projects, clear them out and then just come in here 139 00:07:46,560 --> 00:07:48,060 and select the breakpoint you want. 140 00:07:48,450 --> 00:07:51,270 At this point, we can run it, so we'll just click on that red arrow. 141 00:07:51,870 --> 00:07:53,700 The debugger will engage. 142 00:07:54,210 --> 00:07:55,800 This bottom bar turns orange. 143 00:07:55,800 --> 00:07:58,260 You can see favorite number up here, set to zero. 144 00:07:58,260 --> 00:08:01,230 We never initialized it and we'll talk about that in the class. 145 00:08:01,320 --> 00:08:03,900 Our current executing line is line seven. 146 00:08:03,900 --> 00:08:09,210 So we can execute it by just stepping over, by pressing this icon right here and the output will be 147 00:08:09,210 --> 00:08:09,900 here in terminal. 148 00:08:09,900 --> 00:08:11,190 So you can always click there. 149 00:08:11,190 --> 00:08:13,290 So I'll do that and I'll do it one more time. 150 00:08:13,290 --> 00:08:15,450 It's asking me now for the favorite number. 151 00:08:15,450 --> 00:08:20,670 Again, I'll type 45 one more time and when I press enter now you'll see that I'm stopped at line nine 152 00:08:20,670 --> 00:08:23,790 and favorite numbers value has changed to 45. 153 00:08:23,790 --> 00:08:29,910 And as before, we can hover over that variable name and we can see our value to finish the program. 154 00:08:29,910 --> 00:08:33,780 You can click the play arrow or you can just stop it right here in the debugger. 155 00:08:33,780 --> 00:08:34,860 I'll just continue. 156 00:08:34,890 --> 00:08:35,640 That's it. 157 00:08:35,640 --> 00:08:36,720 So there you go. 158 00:08:36,720 --> 00:08:42,270 This video shows you how to set up the source code provided for the course to work within Visual Studio 159 00:08:42,270 --> 00:08:42,720 code. 160 00:08:42,720 --> 00:08:44,159 So now we can edit. 161 00:08:44,159 --> 00:08:47,040 We can debug and we can build and run.