C++ 11 introduced a mechanism for declaring that a variables 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++ 11 prior to C++ 11, the auto key was used to
declare the automatic variables.
That is, the variables that are automatically allocated in the stack in a function.
So other than variables declared at a full 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++,
so the C++ 11 took advantage of this.
Remove the old meaning and gave the auto the whole new meaning here.
So if you are compiling all C++ code with the C++ 11 compiler and that all 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, simple search and delete each instance of auto.
So it was redundant in C++ prior to C++ 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 a type of the data that
is assigned to it.
So the variable can only have a single type.
The type the compiler decide 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 initial user.
And it means that all auto variables must be initialized.
Now.
Now I want to do some examples here.
So let's create an out variables, which I will explain all of these out variables later and add comments
to it.
For example, 42 auto B 42 L.
Here's how to see 42 WL here.
Auto D here
1.11.0 F auto.
E here.
1.0.
Auto.
If here, uh, if it's going to be character.
Here.
And our two G.
Yes, true.
Here.
Now I want to add 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 a long integer.
So we created long, long integer.
Here we create the float.
Here.
Double.
Not 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.
And here we created the character, just the usual normal standard character.
And here we created the pool here.
So this is a terrible use of the auto keyword use hold.
Some sometimes you create this all together 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 topple or vectors here, which you will learn in later lectures.
So now I want to create a vector that will take to one tuple.
In the tuple we're going to have string and integer.
Here, we're going to create the vector.
As you can see, a vector is not a built in type.
So we have to import from the input class of vector to use it.
And as you can see here, the compiler created the include vector here.
The vector here.
Apple.
String integer here.
So as you can see, we have a toppled and we need to import the string here.
And here we're going to name it my class.
As you can see, we got an error because we didn't actually include that couple here.
So that's why we're going to include include.
Apple.
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 this, cause here, don't worry.
My car's push back, make topple, and we're going to pass the.
For example, let's name some car, BMW.
And it's here.
Here, as you can see, the first is string, and the second parameter is integer.
So and 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.
It's serious.
My cars or push back.
Make topple the fort.
Uh.
Mustang.
Mustang here.
In 1989.
My car's.
The push back.
May topple.
Volkswagen Golf here, 2010.
My constant push back.
Make.
Topple.
Uh, here we're going to import the Land Rover.
Land Rover.
Land Rover?
Yeah.
2015 here.
Now we're going to create a for loop here for, uh, here to pull string integer here.
Uh, it's going to be like my vehicle's.
Here and then.
My car.
We will each rate my cars one by one here, and then we're going to print it out here.
See?
Out, See out.
As you can see, if we cannot, you see it because we have to use a include the STD.
Here.
You start with stream and see what.
Get here.
Get.
My vehicles.
Yeah.
Get.
One.
I will explain all of these quotes.
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 OC.
Make it run it again.
So here, as you can see here, this code uses the vector container here, too.
As you know, we haven't used vector or topos, so don't worry about them.
You will learn in next lectures about, uh, vectors and tuples and other terminologies in C++ here.
But just keep in mind that you will learn it and don't panic here.
So here the vector stores two value items using this tuple.
So the topic class is simple.
You declared a list of the types of items in the top 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 up of function here make the function here.
Is provided by the C++ 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 four calls or the pushback function, the hear the vehicles.
The vehicles variable will contain actual 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 here
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.
Uh, and for loop here.
So an item in the topo here is accessed using the get.
Parameterized function from the tuple here.
As you can see here, this is a gate from this gate function belongs to topple here.
So.
And here, as you can see here, the first sign zero to get the first object of this table and then
a space here and then get one 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 others using the manipulators in next lectures.
So we're going to create here.
Uh, the.
Take a look at the folder up here.
So the type of the.
My vehicles is purple, 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 talk becomes useful.
The here we're going to create a code.
So let's comment it out.
Here.
Oops.
There.
Coleman out.
And here.
For.
Auto my vehicles.
Clothes and my cars and see out.
Get zero.
Phone the my vehicles.
Vehicles and.
Here.
Get one of my vehicles here and end line.
So here.
This is the where auto becomes useful here.
So this code is the same but easier to read.
So the my vehicle's variable is still typed.
It has a topper string integer, but auto means you do not have to explicitly call this in like this
example here.
So this is more readable code and more useful on this case here.