Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (54 sloc) 5.63 KB

(C++) STL

The STL (an abbreviation of 'Standard Template Library') is the standard C++ library consisting of about twenty header files.

The STL is a collection of data types, functions, algorithms and more as described in the C++ Standard. To use a certain data type, function, algorithm or other, the right header file must be #included.

There is no such thing as 'the STL' as a collection of code. Although the requirements of all STL elements is described in the C++ Standard, there exist multiple implementations of those requirements.

Example: Hello World

This Hello World includes the STL header file iostream, so that the STL output stream std::cout can be used:

#include <iostream>

int main() 
{
  std::cout << "Hello World\n"; 
}

Advice

  • Familiarize yourself with the STL [1,3] and the STL-related web sites [2]
  • Prefer the STL to other libraries and to handcrafted code [4,12,13]
  • Use STL facilities to maintain portability [5,14]
  • Use STL facilities to minimize maintenance costs [6]
  • Using STL functions and classes shortens program development time [13]
  • Use STL facilities as a base for more extensive and more specialized libraries [7]
  • Use STL facilities as a model for flexible, widely usable software [8]
  • The STL facilities are defined in namespace std and found in standard-library headers [9]
  • Do no try to use a STL facility without #including its header [11]

External links

STL related website (suggested from [2]):

References

  • [1] Scott Meyers. Effective C++ (3rd edition). ISBN: 0-321-33487-6. Item 53: Familiarize yourself with the standard library, including TR1
  • [2] Scott Meyers. Effective STL. ISBN: 0-201-74962-9. Item 50: 'Familiarize yourself with STL-related web sites'.
  • [3] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Page 32, 1.5 'Advice', item 12: 'Use libraries, especially the standard library, rather than trying to build everything from scratch'
  • [4] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 10.6. Advice. page 271: '[1] Prefer the standard library to other libraries and to "handcrafted code"'
  • [5] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 30.5. Advice. page 883: '[1] Use standard-library facilities to maintain portability'
  • [6] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 30.5. Advice. page 883: '[2] Use standard-library facilities to minimize maintenance costs'
  • [7] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 30.5. Advice. page 883: '[3] Use standard-library facilities as a base for more extensive and more specialized libraries'
  • [8] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 30.5. Advice. page 883: '[4] Use standard-library facilities as a model for flexible, widely usable software'
  • [9] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 30.5. Advice. page 883: '[5] The standard-library facilities are defined in namespace std and found in standard-library headers'
  • [10] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 30.5. Advice. page 883: '[6] A C standard-library header X.h is presented as a C++ standard-library header in <cX>'
  • [11] Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 30.5. Advice. page 883: '[7] Do no try to use a standard-library facility without #including its header'
  • [12] C++ Core Guidelines: SL.2: Prefer the standard library to other libraries
  • [13] Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 1.2, Performance Tip 1.1. page 3: 'Using C++ Standard Library functions and classes instead of writing your own versions van improve program performance, because they're written carefully to perform efficiently. This technique also shortens program development time.'
  • [14] Paul Deitel, Harvey Deitel. C++11 for programmers (2nd edition). 2014. ISBN: 978-0-13-343985-4. Chapter 1.2, Portability Tip 1.1. page 3: 'Using C++ Standard Library functions and classes instead of writing your own improves program portability, because they're included in every C++ implementation'
You can’t perform that action at this time.