1 00:00:01,310 --> 00:00:09,710 C++ 11 introduced a mechanism for declaring that a variables type should be determined from the data 2 00:00:09,710 --> 00:00:14,960 it is initialized with, and that is the auto keyword here. 3 00:00:15,500 --> 00:00:25,190 So this is a minor confusion here because the prior C++ 11 prior to C++ 11, the auto key was used to 4 00:00:25,190 --> 00:00:27,050 declare the automatic variables. 5 00:00:27,080 --> 00:00:32,210 That is, the variables that are automatically allocated in the stack in a function. 6 00:00:32,210 --> 00:00:40,280 So other than variables declared at a full scope or a static, are the other variables in this course 7 00:00:40,400 --> 00:00:46,970 so far have been automatic variables, and automatic variables are the most widely used storage class. 8 00:00:47,660 --> 00:00:57,310 So since it was optional and applicable to most variables, the auto keyword was rarely used in C++, 9 00:00:57,320 --> 00:01:00,680 so the C++ 11 took advantage of this. 10 00:01:00,800 --> 00:01:07,770 Remove the old meaning and gave the auto the whole new meaning here. 11 00:01:07,790 --> 00:01:17,360 So if you are compiling all C++ code with the C++ 11 compiler and that all code uses auto, so you will 12 00:01:17,360 --> 00:01:26,330 get errors because the new compiler will assume auto will be used with the variables with no specified 13 00:01:26,330 --> 00:01:27,110 type. 14 00:01:27,350 --> 00:01:28,310 So. 15 00:01:29,300 --> 00:01:34,340 If this happens, simple search and delete each instance of auto. 16 00:01:34,340 --> 00:01:42,780 So it was redundant in C++ prior to C++ 11 and there was a little reason for developers to use it. 17 00:01:42,800 --> 00:01:50,570 Here, the auto keyword means that the compiler should create a variable with a type of the data that 18 00:01:50,570 --> 00:01:51,710 is assigned to it. 19 00:01:51,710 --> 00:01:55,290 So the variable can only have a single type. 20 00:01:55,310 --> 00:02:00,170 The type the compiler decide is a type it needs for the data assigned to it. 21 00:02:00,590 --> 00:02:06,740 So and you cannot use the variables elsewhere to hold data of a different type because the compiler 22 00:02:06,740 --> 00:02:10,220 needs to determine the type from an initial user. 23 00:02:10,640 --> 00:02:16,340 And it means that all auto variables must be initialized. 24 00:02:17,330 --> 00:02:17,780 Now. 25 00:02:18,290 --> 00:02:21,210 Now I want to do some examples here. 26 00:02:21,230 --> 00:02:28,130 So let's create an out variables, which I will explain all of these out variables later and add comments 27 00:02:28,130 --> 00:02:28,640 to it. 28 00:02:29,660 --> 00:02:35,090 For example, 42 auto B 42 L. 29 00:02:36,330 --> 00:02:41,140 Here's how to see 42 WL here. 30 00:02:41,160 --> 00:02:44,160 Auto D here 31 00:02:45,720 --> 00:02:50,250 1.11.0 F auto. 32 00:02:51,160 --> 00:02:52,030 E here. 33 00:02:53,560 --> 00:02:55,660 1.0. 34 00:02:57,040 --> 00:02:57,910 Auto. 35 00:02:59,910 --> 00:03:04,890 If here, uh, if it's going to be character. 36 00:03:10,800 --> 00:03:11,280 Here. 37 00:03:15,090 --> 00:03:16,560 And our two G. 38 00:03:18,630 --> 00:03:19,920 Yes, true. 39 00:03:22,350 --> 00:03:22,890 Here. 40 00:03:23,730 --> 00:03:28,650 Now I want to add variables after it. 41 00:03:28,800 --> 00:03:38,600 So this is the integer we created integer type because we assigned to just an integer. 42 00:03:38,610 --> 00:03:43,800 And here we created the long type, just a long integer. 43 00:03:44,610 --> 00:03:47,820 So we created long, long integer. 44 00:03:49,040 --> 00:03:51,620 Here we create the float. 45 00:03:52,530 --> 00:03:53,700 Here. 46 00:03:54,660 --> 00:03:55,470 Double. 47 00:03:57,060 --> 00:04:04,740 Not that there is no syntax to specify that an integer value is a single byte or two byte, so you cannot 48 00:04:04,740 --> 00:04:11,160 create an unsigned character variables or short variables this way. 49 00:04:12,240 --> 00:04:17,340 And here we created the character, just the usual normal standard character. 50 00:04:18,570 --> 00:04:21,420 And here we created the pool here. 51 00:04:22,690 --> 00:04:29,080 So this is a terrible use of the auto keyword use hold. 52 00:04:30,580 --> 00:04:37,420 Some sometimes you create this all together with this and the compiler will assign the type of this 53 00:04:37,420 --> 00:04:39,280 variable automatically. 54 00:04:39,520 --> 00:04:44,370 So now I want to create another example to show you how this happens. 55 00:04:44,380 --> 00:04:48,940 And here this things might might get confusing. 56 00:04:48,940 --> 00:04:56,830 So don't worry if you don't know about the topple or vectors here, which you will learn in later lectures. 57 00:04:57,160 --> 00:05:03,160 So now I want to create a vector that will take to one tuple. 58 00:05:03,790 --> 00:05:06,880 In the tuple we're going to have string and integer. 59 00:05:08,240 --> 00:05:10,220 Here, we're going to create the vector. 60 00:05:10,460 --> 00:05:13,270 As you can see, a vector is not a built in type. 61 00:05:13,280 --> 00:05:18,890 So we have to import from the input class of vector to use it. 62 00:05:19,040 --> 00:05:23,330 And as you can see here, the compiler created the include vector here. 63 00:05:24,560 --> 00:05:25,850 The vector here. 64 00:05:26,210 --> 00:05:26,900 Apple. 65 00:05:28,420 --> 00:05:30,700 String integer here. 66 00:05:30,940 --> 00:05:37,840 So as you can see, we have a toppled and we need to import the string here. 67 00:05:39,950 --> 00:05:43,280 And here we're going to name it my class. 68 00:05:44,490 --> 00:05:50,580 As you can see, we got an error because we didn't actually include that couple here. 69 00:05:50,580 --> 00:05:54,690 So that's why we're going to include include. 70 00:05:55,420 --> 00:05:56,010 Apple. 71 00:05:56,650 --> 00:05:59,770 As you can see here, our error gone away. 72 00:06:00,250 --> 00:06:01,330 And then. 73 00:06:02,770 --> 00:06:03,340 Here. 74 00:06:03,880 --> 00:06:10,330 We're going to add variables to my car's vector here, my cars. 75 00:06:10,330 --> 00:06:12,790 I will explain all of this, cause here, don't worry. 76 00:06:13,420 --> 00:06:19,960 My car's push back, make topple, and we're going to pass the. 77 00:06:22,150 --> 00:06:24,850 For example, let's name some car, BMW. 78 00:06:25,030 --> 00:06:26,320 And it's here. 79 00:06:26,320 --> 00:06:32,350 Here, as you can see, the first is string, and the second parameter is integer. 80 00:06:32,350 --> 00:06:44,050 So and let's input our the date of production, the year of production of our car, for example, 2001 81 00:06:44,290 --> 00:06:47,890 my cars or let's make a model of it. 82 00:06:47,890 --> 00:06:49,480 So make it look nicer. 83 00:06:53,320 --> 00:06:54,530 It's serious. 84 00:06:55,210 --> 00:06:58,090 My cars or push back. 85 00:06:58,810 --> 00:07:02,020 Make topple the fort. 86 00:07:03,400 --> 00:07:04,480 Uh. 87 00:07:05,790 --> 00:07:06,600 Mustang. 88 00:07:06,960 --> 00:07:08,820 Mustang here. 89 00:07:09,970 --> 00:07:11,520 In 1989. 90 00:07:12,450 --> 00:07:13,740 My car's. 91 00:07:14,600 --> 00:07:16,400 The push back. 92 00:07:17,720 --> 00:07:19,070 May topple. 93 00:07:21,300 --> 00:07:25,410 Volkswagen Golf here, 2010. 94 00:07:26,750 --> 00:07:29,210 My constant push back. 95 00:07:29,940 --> 00:07:30,780 Make. 96 00:07:30,870 --> 00:07:31,410 Make. 97 00:07:31,450 --> 00:07:32,250 Topple. 98 00:07:33,410 --> 00:07:38,000 Uh, here we're going to import the Land Rover. 99 00:07:38,720 --> 00:07:40,280 Land Rover. 100 00:07:41,600 --> 00:07:43,520 Land Rover? 101 00:07:44,310 --> 00:07:44,430 Yeah. 102 00:07:46,260 --> 00:07:49,490 2015 here. 103 00:07:50,220 --> 00:07:59,700 Now we're going to create a for loop here for, uh, here to pull string integer here. 104 00:07:59,860 --> 00:08:03,390 Uh, it's going to be like my vehicle's. 105 00:08:06,100 --> 00:08:08,050 Here and then. 106 00:08:09,370 --> 00:08:10,540 My car. 107 00:08:10,570 --> 00:08:17,620 We will each rate my cars one by one here, and then we're going to print it out here. 108 00:08:17,620 --> 00:08:18,010 See? 109 00:08:18,010 --> 00:08:20,230 Out, See out. 110 00:08:20,230 --> 00:08:26,440 As you can see, if we cannot, you see it because we have to use a include the STD. 111 00:08:28,000 --> 00:08:28,570 Here. 112 00:08:30,110 --> 00:08:32,870 You start with stream and see what. 113 00:08:34,070 --> 00:08:35,990 Get here. 114 00:08:41,560 --> 00:08:42,220 Get. 115 00:08:43,040 --> 00:08:44,510 My vehicles. 116 00:08:45,880 --> 00:08:46,360 Yeah. 117 00:08:49,480 --> 00:08:50,140 Get. 118 00:08:51,030 --> 00:08:51,800 One. 119 00:08:51,810 --> 00:08:53,340 I will explain all of these quotes. 120 00:08:53,340 --> 00:09:00,570 Don't worry here and get one my vehicles. 121 00:09:02,690 --> 00:09:04,130 And end line. 122 00:09:05,790 --> 00:09:07,710 And let's run our code here. 123 00:09:11,580 --> 00:09:12,060 Okay. 124 00:09:15,030 --> 00:09:17,850 Make it look nice and print it out again. 125 00:09:18,960 --> 00:09:23,430 So this code, as you can see, this is our OC. 126 00:09:23,790 --> 00:09:25,120 Make it run it again. 127 00:09:25,140 --> 00:09:33,910 So here, as you can see here, this code uses the vector container here, too. 128 00:09:34,830 --> 00:09:39,930 As you know, we haven't used vector or topos, so don't worry about them. 129 00:09:40,560 --> 00:09:46,320 You will learn in next lectures about, uh, vectors and tuples and other terminologies in C++ here. 130 00:09:46,410 --> 00:09:51,000 But just keep in mind that you will learn it and don't panic here. 131 00:09:51,630 --> 00:09:58,530 So here the vector stores two value items using this tuple. 132 00:09:59,830 --> 00:10:01,840 So the topic class is simple. 133 00:10:02,080 --> 00:10:09,550 You declared a list of the types of items in the top object and the declaration between the angled braces 134 00:10:09,550 --> 00:10:09,940 here. 135 00:10:09,940 --> 00:10:18,150 So the tuple string integer declaration says that the object will hold a string and an integer. 136 00:10:18,160 --> 00:10:24,850 So in that order, the make up of function here make the function here. 137 00:10:25,850 --> 00:10:34,610 Is provided by the C++ Standard Library and will create a tuple object containing two values. 138 00:10:34,610 --> 00:10:40,070 The first is a string and the second is integer. 139 00:10:40,520 --> 00:10:45,830 So the pushback function will put the item into the vector container. 140 00:10:45,830 --> 00:10:53,120 So after the four calls or the pushback function, the hear the vehicles. 141 00:10:54,440 --> 00:11:03,440 The vehicles variable will contain actual the my car's variable will contain four items and each in 142 00:11:03,440 --> 00:11:11,510 the four items we're going to have two variables and each one is tuple with the name and birth here 143 00:11:12,050 --> 00:11:12,800 and here. 144 00:11:12,800 --> 00:11:22,460 As you can see, the range for loops throughout the container and on each loop assigns the my vehicle 145 00:11:23,000 --> 00:11:27,590 variable with the next item in the container of my cars. 146 00:11:27,680 --> 00:11:34,610 So the values in the tuple are printed to the console, as you can see here in this function. 147 00:11:35,740 --> 00:11:37,240 Uh, and for loop here. 148 00:11:37,240 --> 00:11:43,900 So an item in the topo here is accessed using the get. 149 00:11:45,450 --> 00:11:49,320 Parameterized function from the tuple here. 150 00:11:49,320 --> 00:11:55,380 As you can see here, this is a gate from this gate function belongs to topple here. 151 00:11:56,070 --> 00:11:57,060 So. 152 00:11:59,560 --> 00:12:08,380 And here, as you can see here, the first sign zero to get the first object of this table and then 153 00:12:08,380 --> 00:12:17,470 a space here and then get one gets the year of item in the tuple. 154 00:12:17,470 --> 00:12:22,780 And the result of this code is this output here. 155 00:12:23,200 --> 00:12:30,790 So the next text has poor formatting because it does not take into account the length of the names. 156 00:12:30,790 --> 00:12:35,800 So this can be others using the manipulators in next lectures. 157 00:12:35,800 --> 00:12:38,530 So we're going to create here. 158 00:12:40,000 --> 00:12:41,500 Uh, the. 159 00:12:41,890 --> 00:12:44,230 Take a look at the folder up here. 160 00:12:46,170 --> 00:12:48,630 So the type of the. 161 00:12:49,480 --> 00:12:54,550 My vehicles is purple, string and integer. 162 00:12:54,550 --> 00:12:56,920 So this is fairly simple type. 163 00:12:56,920 --> 00:13:04,780 And as you use the standard template more, you could end up with some complicated type, particularly 164 00:13:04,780 --> 00:13:06,580 when you use iterators. 165 00:13:06,760 --> 00:13:10,780 So this is where our talk becomes useful. 166 00:13:10,810 --> 00:13:13,600 The here we're going to create a code. 167 00:13:15,160 --> 00:13:17,650 So let's comment it out. 168 00:13:19,230 --> 00:13:19,740 Here. 169 00:13:22,810 --> 00:13:23,150 Oops. 170 00:13:25,150 --> 00:13:25,570 There. 171 00:13:28,740 --> 00:13:29,700 Coleman out. 172 00:13:31,060 --> 00:13:32,290 And here. 173 00:13:36,860 --> 00:13:37,430 For. 174 00:13:38,780 --> 00:13:41,210 Auto my vehicles. 175 00:13:43,500 --> 00:13:48,930 Clothes and my cars and see out. 176 00:13:51,300 --> 00:13:53,490 Get zero. 177 00:13:55,100 --> 00:13:58,250 Phone the my vehicles. 178 00:13:59,400 --> 00:14:01,680 Vehicles and. 179 00:14:04,050 --> 00:14:04,680 Here. 180 00:14:06,040 --> 00:14:12,550 Get one of my vehicles here and end line. 181 00:14:14,650 --> 00:14:17,830 So here. 182 00:14:20,740 --> 00:14:23,400 This is the where auto becomes useful here. 183 00:14:23,410 --> 00:14:28,180 So this code is the same but easier to read. 184 00:14:28,180 --> 00:14:32,740 So the my vehicle's variable is still typed. 185 00:14:33,430 --> 00:14:44,410 It has a topper string integer, but auto means you do not have to explicitly call this in like this 186 00:14:44,410 --> 00:14:45,370 example here. 187 00:14:45,430 --> 00:14:50,260 So this is more readable code and more useful on this case here.