Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

STL library

This topic is 6566 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

STL, (Standard Template Library) is a collection of handy tools for the C++ programmer. Resizeable vectors, maps, and a string class are all included, plus code that quicksorts, randomizes, etc.

You can learn more about it by purchasing the book _STL Tutorial and Reference Guide_, by David R Musser and Atul Saini, or by doing a search for STL in your MSDN docs.

It is supposedly standard and cross-platform, tho I've only played around with the VC++ version of it.

Mason McCuskey
Spin Studios
www.spin-studios.com

Share this post


Link to post
Share on other sites
The Standard Template Library is part of the C++ language (it was adopted formally in 1998). It is incredibly useful, providing object-oriented implementations of data structures like strings, dynamic arrays, linked lists, and maps, algorithms such as searching, sorting, counting, etc. Everything is in template form so you can use the STL for any data types. You can use it in Windows and DirectX as long as you are using C++, it won't work with C.

Before you learn STL, you should have a good understanding of templates; otherwise the notation can get pretty confusing. Check out this site for some online tutorials, or (and this is what I'd recommend), pick up C++: The Complete Reference by Herb Schildt. It has excellent coverage of pretty much everything in C++, including STL.

Share this post


Link to post
Share on other sites
STL is where it's at.

One of those stupid things that us programmers do, no matter how much we try to go with code reuse, or use good object oriented, is create a linked list(or stack or something) from scratch every time we need it-

class x{
x* prev;
x* next;

...
}


class y{
y* prev;
y* next;
}

and sure it's not a big deal, but that's how errors or memory leaks sneak in. STL lets you use code for this kind of stuff thats been tested, tested, tested and isn't buggy.

On another post the question just came up again "How do you tell if a linked list loops?" With STL the answer is, it doesn't. With STL you don't have to worry about dereferencing a bad pointer or trying to dereference a NULL one at run-time.

I've had trouble with other compilers (ming) where STL made the executable jump up by 150kb (when it was only 100kb to begin with) but this shouldn't be a problem with MSVC.

(Yes, it's probably a little slower than rolling your own lists, but that's not why you use OO techniques)

Share this post


Link to post
Share on other sites
While I'm a new convert to using STL for many of the "drudge" chores associated with most types of C development, and heartily recommend it, I thought it might be worth noting that the STL isn't necessarily a speed demon. What specifically comes to mind is a comment in _C++ from the Ground Up_ that basically says the vector type is not as efficient as a straight up array. Does it matter? I'm not sure. For whatever speed is sacrificed, the STL does provide alot of power.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Some of the posted notes I've read lately say something about an
STL library. I would like to know more information about it, so where
should I start? Is it difficult to use in a C or C++ program? I would
like to use it with MSVC++, Windows, and DirectX.

Zack

Share this post


Link to post
Share on other sites