C plus plus 11 introduced a mechanism for declaring that a variable's type should be determined from
the data it is initialized with, and that is the auto keyword here.
So this is a minor confusion here because the prior C plus plus 11 prior to C plus plus 11, the auto
key was used to declare the automatic variables.
That is the variables that are automatically allocated on the stack in a function.
So other than variables declared at a file scope or a static, are the other variables in this course
so far have been automatic variables, and automatic variables are the most widely used storage class.
So since it was optional and applicable to most variables, the auto keyword was rarely used in C plus
plus.
So the C plus plus 11 took advantage of this.
Remove the old meaning and gave the author the whole new meaning here.
So if you're compiling all C plus plus code with the C plus plus 11 compiler and that old code uses
auto, so you will get errors because the new compiler will assume auto will be used with the variables
with no specified type.
So.
If this happens, simply search and delete each instance of auto.
So it was redundant in C plus plus prior to C plus plus 11.
And there was a little reason for developers to use it here.
The auto keyword means that the compiler should create a variable with the type of the data that is
assigned to it.
So the variable can only have a single type.
The type the compiler decides is a type it needs for the data assigned to it.
So and you cannot use the variables elsewhere to hold data of a different type because the compiler
needs to determine the type from an initializer.
And it means that all auto variables must be initialized.
Now.
Now, I want to do some examples here.
So let's create an auto variables, which I will explain all of these auto variables later and add comments
to it.
For example, 42 auto be 42.
Here.
Auto c 42 lx here auto d here.
Um 1.11.0 f auto.
E here.
1.0.
Auto.
If here.
Uh, if it's going to be character.
Here.
And auto.
Here.
True.
Here.
Now I want to add, um, variables after it.
So this is the integer we created integer type because we assigned to just an integer and here we created
the long type, just the long integer.
So we created long, long integer.
Here.
We created the float.
Here.
Double note that there is no syntax to specify that an integer value is a single byte or two byte,
so you cannot create an unsigned character variables or short variables this way.
Uh, and here we created the character.
Just a usual normal standard character.
And here we created the bull here.
So this is a tribal use of the auto keyword.
You should some sometimes you create this auto keyword with this and the compiler will assign the type
of this variable automatically.
So now I want to create another example to show you how this happens.
And here this things might might get confusing.
So don't worry if you don't know about the tuple or vectors here, which you will learn in later lectures.
So now I want to create a vector that will take two, uh, one tuple, uh, in the tuple we're going
to have string and integer.
Here, we're going to create the vector.
As you can see here, vector is not a built in type.
So we have to import from the import class of vector to use it.
And as you can see here, the compiler created a include vector here.
The vector here tuple.
String integer here.
So as you can see, we have a tuple and we need to import the string here.
And here we're going to name it my cars.
Uh, as you can see, we got an error because we didn't actually included the tuple here.
So that's why we're going to include include.
Couple here, as you can see here, our error gone away and then.
Here.
We're going to add variables to my car's vector.
Here, my cars.
I will explain all of these codes here.
Don't worry.
My car's pushback back make topple and we're going to pass the.
For example, let's name some car BMW and its year here.
As you can see, the first is string and the second parameter is integer.
So let's input our the date of production.
The year of production of our car, for example, 2001.
My cars.
Or let's make a model of it.
So make it look nicer.
5/5 series here.
My cars push back.
Make Topple.
The fourth.
Uh.
Mustang.
Here.
1989.
My cars.
The pushback.
Make a couple.
Uh, Volkswagen Golf here.
2010.
My car.
Start.
Push back.
Make.
Topple.
Uh, here.
We're going to input the Land Rover.
Land Rover.
Land Rover here.
2015 here.
Now we're going to create a for loop here for here, Tupple string integer here.
It's going to be like my vehicles.
Here and then.
My cars.
We will iterate.
My cars one by one here, and then we're going to print it out here.
C out.
As you can see, we cannot use C out because we have to use a include STD.
Here.
Input output stream and see.
Get here.
Get.
My vehicles.
Here.
Get.
One.
I will explain all of these codes.
Don't worry.
Here.
And get one.
My vehicles.
And end line.
And let's run our code here.
Okay.
Make it look nice and print it out again.
So this code, as you can see, this is our okay, make it run it again.
So here, as you can see here, this code uses the vector container here to as you know, we haven't
used vector or tuples, so don't worry about them.
You will learn in next lectures about vectors and tuples and other technologies in C plus plus here.
But just keep in mind that you will learn it and don't panic here.
So, uh, here the vector stores two value items using this tuple.
So the tuple class is simple.
You declare a list of the types of items in the tuple object and the declaration between the angled
braces here.
So the tuple string integer declaration says that the object will hold a string and an integer.
So in that order, the make tuple function here make tuple function here.
Is provided by the C plus plus standard library and will create a tuple object containing two values.
The first is a string and the second is integer.
So the pushback function will put the item into the vector container.
So after the for cost of the pushback function, the here the vehicles.
The vehicle's variable will contain actually the my car's variable will contain four items and each
in the four items we're going to have two variables and each one is tuple with the name and birth year.
And here, as you can see, the range for loops throughout the container and on each loop assigns the
my vehicle variable with the next item in the container of my cars.
So the values in the tuple are printed to the console, as you can see here in this function.
And for loop here.
So an item in the tuple here is accessed using the get.
Parameterized function from the tuple.
Here, as you can see here, this is a get function.
This get function belongs to tuple here.
So.
And here, as you can see here, the first we assigned zero to get the first object of this tuple and
then a space here and then get one, uh, gets the year of item in the tuple.
And the result of this code is this output here.
So the next text has poor formatting because it does not take into account the length of the names.
So this can be addresses using the manipulators in next lectures.
So we're going to create here.
Uh, take a look at the for loop here.
So the type of the.
My vehicles is tuple, string and integer.
So this is fairly simple type and as you use the standard template more, you could end up with some
complicated type, particularly when you use iterators.
So this is where our tool becomes useful.
The here we're going to create a code.
Okay, so let's comment it out.
Here.
Oops.
Here.
Commented out.
And here.
For.
Autonomy vehicles.
Girls and my cars and see out.
Get zero.
From the my vehicles.
Vehicles and.
Here.
Get one from the my vehicles here and end line.
So here.
This is where R2 becomes useful here.
So this code is the same but easier to read.
So the my vehicles variable is still typed.
It has a tuple string integer, but auto means you do not have to explicitly code this in like this
example here.
So this is more readable code and more useful on this case here.