Edgar Huckert: C++/STL samples
STL means "standard template library". Twenty years ago the C++ STL
library was in its beginnings
and was very complex and not very reliable. Every C++ programmer
(including me) had his own implementations for concepts
like string or list. Large GUI libraries
like wxWidgets still have their own string and list classes.
Note that the STL is not the same type of library as
the normal ones: STL is completely implemented on the
preprocessor level. Normally
(there are exceptions!) you will not find someting like
libstl.a,libstl.so (Unix) or libstl.dll/libstl.lib (Windows).
You don't need to link an extra library when you use STL.
Things have
improved in the mean
time. I use STL now from time to time - especially when it comes to
integrate foreign source code.
Here are some simple source code files that test the most frequently used
classes:
- list from the
the container classes implemented in C++/STL.
Other important container classes are map, multimap, queue.
This class can be used when it comes to return multiple results
from a database search.
- multimap. This
class allows associative access to the members, i.e. values
are typically retrieved by specifying a key. In contrast to the
STL class map this class allows multiple keys. If you want
for example retrieve all CDs in your collection where John Coltrane
was the soloist and if you have given these CD records
the same key "COLTRANE"
then you get all values with this key, i.e. you get as result
a collection instead of a single value. I use this class
to implement retrieval and storage in Windows like ini files (although
ini files normally do not support multiple keys). You may thus get
all contents contained in a single section of an ini-file if
you have used the section name as key.
- vectors: the class
vector
(another container class) is an appropriate way to implement arrays with
variable size. In contrast
to classes like list it offers direct access to the
elements. i.e. via index numbers. In newer implementations of
STL you may find a class array which is probably faster
than vector but offers no variable size.
- strings: here the standard
string class. A warning: not
all C++ compilers are on the same standardization
level (C++98, C++11 etc)! Another
important note: this program tests only the standard
C++ strings (based on the char data type, one byte per character).
- wide strings: here is a sample for the standard
wstring class. This
class uses wchar_t (normally two bytes per character) as basic data type.
Note that some of these classes require knowledge about
the concept of templates which is not explained here.
Copyright for all images, texts and software on this page: Dr. E. Huckert
Contact
If you want to contact me: this is my
mail address