CIS-60 Home http://www.c-jump.com/CIS60/CIS60syllabus.htm

C++ Standard Library, the STL


  1. C++ Standard Library
  2. STL components for generic programming
  3. Example of STL containers
  4. Example of STL swap algorithm
  5. STL Containers
  6. std::stack
  7. std::set
  8. std::pair
  9. Functions returning a pair
  10. STL Iterators
  11. std::map
  12. std::string

1. C++ Standard Library



2. STL components for generic programming



3. Example of STL containers



4. Example of STL swap algorithm



5. STL Containers



6. std::stack



7. std::set



8. std::pair

  • 
    std::pair< T1, T2 >
    
    

    is a C++ structure that holds one object of type T1 and another one of type T2:

    
        #include <cassert>
        #include <string>
        #include <utility>
        using namespace std;
        int main (int argc, char* argv[])
        {
            pair< string, string > strstr;
            strstr.first = "Hello";
            strstr.second = "World";
    
            pair< int, string > intstr;
            intstr.first = 1;
            intstr.second = "one";
    
            pair< string, int > strint( "two", 2 );
            assert( strint.first == "two" );
            assert( strint.second == 2 );
    
            return 0;
        }
    
    
  • A pair is much like a container that holds exactly two elements.

  • The pair is defined in the standard header named utility.

9. Functions returning a pair



10. STL Iterators



11. std::map



12. std::string