 Hello and welcome to the NPTEL course on an introduction to programming through C++. I am Abhiram Ranade and today's lecture is on the standard library of C++. This is discussed in chapter 22 of the text. So the standard library comes with every C++ distribution and it contains many functions and classes that you are likely to need in day to day programming. These classes have been optimized and debugged thoroughly. So if you use them, they will be reliable and you may be able to write programs with very little work. So definitely use them if the need arises. So definitely do not invent your own classes but learn these classes and use them. So here is what we are going to do in this lecture. So I am going to talk about the string class. So in the last lecture we talked about a class that we ourselves designed and which we called string but with a capital S. So this is going to be string but with everything lower case. In some sense this class is implemented in a manner similar to our capital string class. And in fact all the classes that I am going to talk about will have implementations which will need the heap memory. So they will deallocate and allocate heap memory but yet all of those things will happen behind the scenes and to that extent the implementations will be similar to capital string class implementation which we had. But of course these classes are going to do something different. So there will be differences as well and in this course as well we are not going to talk about exactly how these classes are implemented. But just to get a sense that how they might be implemented we have discussed the capital string class. So you will have some understanding. All of this will not seem like too much magic to you. So we will talk about the string class, we will talk about a class called a vector class and we will talk about classes a map and unordered map and then we will conclude. So the string class from the library. So this is a much more powerful version of the string class we developed in chapter 21. There are more constructors, concatenation is still there using plus and you can directly print out or read into strings. So you do not have to go through null terminated arrays or anything like that. And there are operations for extracting substrings or finding one string inside another. So we are going to see some examples. This is not going to be a comprehensive discussion of the string class. For that I will recommend that you look at the online documentation. So to use this class you need to include the header file string. So here is how you might use it. So I might create a string and while creating I might initialize it to this string constant abc dab. Now I can write string w and in parenthesis I can write a string from which you are going to copy that string. So this is another constructor but this copies directly. So that v is directly copied. So I could have written this as string w equal to v as well but this is another style of writing initial values. I can write string x equal to v plus w. So that is just concatenation and the concatenation is put into string x. I can index and the index operations can be on both sides. So in this particular case v2 is changing to v3. So we had abc dab before. So that will now become abd dab. Here is an interesting operation. So we are doing cout v dot substring I guess there should be a semicolon over here. But anyway so that the substring 2 means the substring of v starting at 2. So this is v so this is 0, 1, 2, 0, 1, 2 but remember that we just change this c to d. So the substring of this v starting at 2 will be ddab. So v dot substring 1, 3 says that I want a substring which starts at 1 but whose length is 3. So substring of v which starts at 1. So v is now this, so 0, 1 so it starts at b but its length is 3 so this will be bdd. So for this part we will end up printing bdd. Then we can find, we can look for strings inside a given string. So for example I can write v dot find so this is our v and we are finding ab inside it. So where does ab appear? So it appears at 0 so this will return 0. But suppose I execute v from position 1. So this says find ab but execute it from position 1. So this is our current v so I am not going to start over here, I am going to start over here. So in this case my occurrence is going to be at this is 0, 1, 2, 3, 4 so this should be at occurrence 4. So this will end up printing 0 and 4 because I will be set to 0 and j will be set to 4. So the find function needs some explanation because if the find member function does not find the argument in the receiver then it returns a constant string colon colon n pos. So which is not a valid index so what you can do is you can check whether the returned index equals string colon colon n pos. So that way you know that the string is not present. So going back over here if we were looking for say x, y then I would have been set to string colon colon n pos. So n pos probably is some negative value for example so which cannot be the position of any occurrence. So that is how you can check whether the string actually appears or does not appear. So a string object can be passed by a value in which case it is copied or by reference. So if you are passing strings to a function this is how you can do both but of course I mean the usual rules apply. String objects can also be compared and for this the lexicographical order which we talked about some time ago is used the dictionary order. So just to clarify A, B, C, D, E, F appears earlier in the dictionary so this will be deemed smaller than this. So here is an exercise for you write a function which counts the number of occurrences of one string inside another. So in our old string there were two occurrences so your function should compute you should print out both the occurrences. So you will have to use the find command in slightly imaginative manner. So what have we discussed? So we have discussed some features of the string class which is a powerful safe way of handling text data. So you really should try to use this string class as much as possible and avoid null terminated care arrays because those are quite error-prone and also cumbersome. In the next segment we are going to talk about a class called the vector class but before we do that let us take a short break.