So, in our vector program in the last segment you saw that we used this very complicated declaration for the variable it, the local iterator. Variable and that's where again auto is so important as is mentioned earlier. Auto is not at all what it started out to be in old c. In old c it was storage classification and c++ auto is a type inference mechanism. So, here the compiler looks and says it has to be of an appropriate type for data.begin, and if you remember, data.begin is where the beginning of that vector which is for storing a bunch of integers in, so it would infer that whole standard vector int colon colon iterater logic and you don't have to write it And it's quite transparent as to what is going on. And you're back to just using it, a sentinel, and then auto-incrementing the pointer type so that you can march through for how many elements, and Fill your vector. So, here's all the STL value. We've used the iterator idiom for the vector. Make sure we go correctly across the whole container. We don't have any. Possibility of making indexing errors right? That's a value anybody that's programmed in C knows that we seg faults, or some other fancy message at run time if somehow we index out of the range of the array. And this is a way to avoid that so this is one of the very strong values of moving over to the iterator idiom and the range begin and end and again I say, you'll see that over and over in the STL library. And as part of the idiom, we see the auto increment of the pointer throughout and then we see the dereferencing and processing of the item and you can just as well imagine that instead of this process This could be processing start p in a very complicated way, taking each element in time and doing something with it. Not just this rather rudimentary printing it. You could even call a whole function on it to Do some fancy stuff with it. Okay, quiz, avoiding bounds errors. For(int i =0; i<=upper_bound ++i, sum = sum + data[i]. Can you find something wrong? Think C. Think what's wrong if this is the conventional C idiom. Upper_bound is normally not tested. Like that, it's normally tested with this. So, this is going to get you one pass where you look, and going one pass is going to result in some kind of run time error, and again, conventionally, this is thought of as an off-by one error. And that's what we're trying to get you to avoid. So, again, to demonstrate how powerful STL is, we're going to use the STL iterator standard library. We're gonna use the file stream library, and we are gonna do something where text where we get data from a local standard file. So, there you can be processing arbitrary amounts of data. It's just,some experimenter has given you the weights of elephant seals, that's what we do out here at UCSC, we or right next to the breeding ground that the elephant seals and you decide you want to know what the average weight of the elephant seals are, and you have a bunch of data which is integer data, it turns out actually elephant seals can be up to. Six or seven thousand pounds despite the males get quite a bit bigger than the females. So, if you're a Biologist and you are tracking a lot of this, this is very useful and this is very common again in all sorts of. Data science. You have some big files, you're processing them, and you're trying to find key, important statistics out of those files. How do we do this? Well the first thing we do, which is again very simple because of SDL, is we have an if-stream. A data file and the local name, the local file name. So, that's gonna be called data.txt. We have an iterator for the type of data that'll be stored there which is gonna be an int. And we have two pointers. A start pointer and an end pointer. And the start pointer is going to be initialized to the beginning of the file. So, the file's name locally is data.txt. Start points at wherever we go to open that file, and end will end up being the sentinel for the end of that file. Now, here's what's fascinating about SDL. Here's a constructor type and it has two arguments. One of the arguments is, they're both iterators. They're iterators to something else, namely an istream. One is the start of the istream and one is the end of the istream. So, this is going to generate fancy code that you don't have to use. That's why it's so powerful. It itself is going to do an initialization out of that text file of all the integers found in that text file. And it's arbitrary so we don't know in advance how many we need And because vector itself is an expandable sequential container, the system will build it. And that data's all going to end up sitting here in the internal variable data. Now, we can process the data, and notice we, let's say in this case we want an average. So, we're gonna sum the data, initialize the sum to 0. We're gonna use auto to get the right type for the iterator. That's the star Which had been initially to the beginning of the file. And we're gonna go to the end. And we're gonna do the sum. And then We can print out the sum and then we can find the average of the sum. Of course I use 1.0 so it ends up in the double domain. You should all be aware that we could have just as well done that with a static_ cast.