1 / 11

Standard Template Library (STL)

Standard Template Library (STL). EECE 351 Spring 2000 Lecture # 23. Overview. What STL is How to use it 2 things that would be good to know: vector string Lab Vector palindrome recognizer What we know Where we are going. STL What it is.

sondra
Download Presentation

Standard Template Library (STL)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Standard Template Library (STL) EECE 351 Spring 2000 Lecture # 23 EECE 351 – Lecture 23

  2. Overview • What STL is • How to use it • 2 things that would be good to know: • vector • string • Lab • Vector palindrome recognizer • What we know • Where we are going EECE 351 – Lecture 23

  3. STLWhat it is • STL is a list of header files (and a library [*.lib] of their implementation). • A wonderful thing! • Because STL uses templates, their items can be anything (ints, floats, chars, etc.). • Aside from data structures: • Linked lists, stacks, queues, etc. (containers) • They also provide algorithms: • Search, sort, etc. EECE 351 – Lecture 23

  4. STL What it is (cont.) • Another great thing they give us is the string class. • More powerful than char*. • We also have something called namespaces. • This allows us to declare two items with the same name in the same program. (See handout.) • To use STL, we need to use different header files. • And say we are using a namespace. EECE 351 – Lecture 23

  5. STL How to use it • For example: • #include <iostream.h> • Becomes: • #include <iostream> • using namespace std; • Mixing these two causes problems, as we will see. • Then we declare objects (or pointers) to use. EECE 351 – Lecture 23

  6. STL – 2 Great thingsVector • Storage class • Dynamically grows/shrinks • Has its own member functions: • size – returns the number of elements. • push_back – places given item into array. • pop_back – removes last element. • Each element is accessed like an array. • Review handout. EECE 351 – Lecture 23

  7. STL – 2 Great thingsString • Similar to char* • Much, much, more powerful • Has a lot more functionality: • Operators • += (add 2 strings together), [] (array indexing), etc. • Functions • Length (return # of items in string) • c_str (converts string to char*) • Many more (review handout.) EECE 351 – Lecture 23

  8. Lab • Some of your classmates convinced me to not assign another homework. • Gives you time to: • Resub the ones you have already done. • Work on the project! • Use this time wisely!!! • You should examine the code and attempt the following activities. • First, change <fstream> to <fstream.h>. • Note errors: EECE 351 – Lecture 23

  9. Labcont. • Comment #pragma line. • Comment using namespace std; line. • Make n2 = vStrings.size() [take out the "-1"]. What semantic error is produced? Why? • Alter the input file. Can you find a setup that doesn’t work? • Moving EOF doesn’t count! EECE 351 – Lecture 23

  10. What we know • STL • Lab – Vector palindrome recognizer EECE 351 – Lecture 23

  11. Where we are going • Software Engineering: • No Silver Bullets • Your chance to evaluate me!! • Uh-oh!!!! • Quiz & Project questions • Final Review • The Exam • Summer!!! EECE 351 – Lecture 23

More Related