What is STL?
STL is part of Visual C++. Its a library that has sequences, containers, iterators and algorithms. It comes with Visual C++ compiler. Owner of this library is a third party company, that is Microsoft's partner and Microsoft manages partnership with them and working with them for enhancing STL and fixing bugs. Often your program does sorting, searching, replacing, adding or removing, and STL gives you template classes and containers and iterators for all of this, you can use these template to make your program more reliable, robust and more secure without any headache and effort. Programmers, some of them use STL for these common sorting, searching and many more, some of them don't use and some of them don't know what STL is or might be they don't like STL.
Why we use STL?
If you go through implementation of all these basic algorithms in your program, it takes lot of time and effort while you don't have time in most cases. Most of time you have very tight deadlines and sometimes you have limited men power and you don't want your application to be crashed because of memory leakages. Or perhaps you need to change size of your arrays when you get change in requirements or change in scenario or change in solution that you made for that scenario. And doing all this manually creates lot of key problems like :
- Possible memory leakages and application crashes
- Memory overflow problems
- Because of memory overflow your application becomes less secure
- Time (Your project doesn't meet specified deadline)
For avoiding all these problems, you need a library that can be helpful to you for implementing an efficient solution. STL gives you all basic algorithms and container classes.
What's impact of STL on Application Speed?
As we all know that C++ application is fast enough as compared to those applications developed in other languages. Now if you are thinking that STL makes your program slow and algorithms implemented inside STL are not efficient and they are making your application slow, then I want to tell you that this is wrong assumption and this is a myth about STL. STL is developed by professionals who are highly experienced and highly skilled, those guys are being paid only for analyzing the code inside STL and for making it faster, optimized, secure and more reliable. It will not draw any bad impact on your C++ application. Your application will work faster as it does now.
Very easy to use
Finally I will give you a sample program, that will help you to understand how easy it is. If you are C programmer or you are one who is doing all these kinds of stuff manually then I will suggest you that you just change the way you are thinking about solution. It will help you a lot to understand STL and to get inside STL. Here I will show you a sample program, that uses "vector" that is a template class inside STL.
#include <vector>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> v_int; //Declaring a int type vector
//Inserting elements inside vector
v_int.push_back(110);
v_int.push_back(335);
v_int.push_back(775);
for(size_t i = 0; i < v_int.size(); i++)
cout<<v_int[i] << endl;
return 0;
}
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> v_int; //Declaring a int type vector
//Inserting elements inside vector
v_int.push_back(110);
v_int.push_back(335);
v_int.push_back(775);
for(size_t i = 0; i < v_int.size(); i++)
cout<<v_int[i] << endl;
return 0;
}
For learning more about STL, please click here C++ STL
This video might be helpful to you Standard Template Library in Visual C++