whats the use of STL?
The standard template library contains common data structures and algorithms for use in C++ programs. If you need to, for example, a sort a range, you can just use std::sort(). Your favorite C++ reference should be able to provide a comprehensive list of components supplied by the STL.
It saves the developer from reinventing the wheel. It's full of useful data structures and algorithms, like linked lists, vectors, strings, hash tables, along with sorting algorithms and so on.
Rather than roll your own bug-ridden linked list and a crappy bubble sort, you can just use std::lists and their built in sort functionality. It's pretty fast, it's (mostly) bug free, and you don't have to bother coding it yourself.
Rather than roll your own bug-ridden linked list and a crappy bubble sort, you can just use std::lists and their built in sort functionality. It's pretty fast, it's (mostly) bug free, and you don't have to bother coding it yourself.
is it easy to use?
do you have to include a bunch a files and link libraries and
set the include directories?
do you have to include a bunch a files and link libraries and
set the include directories?
It's all contained in the header files, so there's no libraries to link to.
As for ease of use... you might want to get a book or find some tutorials on the subject. There's lots of functionality in the STL, and the syntax might seem a bit unusual at first. It's also quite important to know about all the components on offer so you can choose the best tool for the job - if you use an stl vector when a list would be better suited, for example, your performance and memory usage could suffer considerably.
As for ease of use... you might want to get a book or find some tutorials on the subject. There's lots of functionality in the STL, and the syntax might seem a bit unusual at first. It's also quite important to know about all the components on offer so you can choose the best tool for the job - if you use an stl vector when a list would be better suited, for example, your performance and memory usage could suffer considerably.
As guys abopve wrote - you should use it properly but itself is very easy to use.
for example
for example
#include <vector> // header for 'std::vector' ...void test(void){ std::vector<int> test_vector; // declare STL vector with int elements - it's like an array, except that you can set its size test_vector.resize(10); // set size to 10 element for(usnigned int i=0; i<10; i++) // fill in test_vector = i; test_vector.resize(5); // decrease size to 5 elements for(usnigned int i=0; i<test_vector.size(); i++) // iterate thru element and print them printf("%d ", test_vector );}output will be: 0 1 2 3 4...
You can do such a resizable array with new[] and delete[].
But vector is superior - not olnly is easier to use but it protects you from having memory leaks in your program - you won't forget to call delete because there's no need to do it.
And last thing - STL includes containers like vector and a bunch of alghoritms that can do many things 'for you'
Quote:Original post by tomek_zielinski
you won't forget to call delete because there's no need to do it.
Unless you use it to store pointers
andyb716: The STL is there to give you a bunch of 'standard' libraries that are very well tested and usefull in most any application. You can either go and be the Nth person to eg. write a linked list or use std::list instead. Unless you really need something special, the STL will usually do the job just fine.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement