Jump to content
  • Advertisement
Sign in to follow this  

whats the use of STL?

This topic is 5064 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
As guys abopve wrote - you should use it properly but itself is very easy to use.

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
...

Share this post


Link to post
Share on other sites


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'

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
thanks for your comments. Is there a really good place to find tutorials. I searched google and a bunch came up and I don't what one to look at.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!