Stl-sol - The Standard Template Library Tutorial 184.437...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
The Standard Template Library Tutorial 184.437 Wahlfachpraktikum (10.0) Johannes Weidl Information Systems Institute Distributed Systems Department Technical University Vienna Sunday, 26. November 1995 Exercise Solution Part Advisor Dipl. Ing. Georg Trausmuth Professor DI Dr. Mehdi Jazayeri
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Table of contents Exercise 4.1.1:. ........................................................................................................................... 3 Exercise 4.1.2:. ........................................................................................................................... 3 Exercise 4.1.3:. ........................................................................................................................... 4 Exercises 4.1.4 and 4.1.5:. ......................................................................................................... 5 Exercise 4.2.1:. ........................................................................................................................... 7 Exercise 4.3.1:. ........................................................................................................................... 7 Exercise 4.3.2:. ........................................................................................................................... 8 Exercise Solutions page 2 Johannes Weidl
Background image of page 2
Exercise Solutions Exercise 4.1.1: #define __MINMAX_DEFINED // use STL's generic min and max templates #include "vector.h" // include STL vector implementation #include <iostream.h> void main (void) { vector<int> v(5); // define a vector of int and // reserve memory for five elements for (int i = 0; i < 5; i++) v[i] = 2*i; // store arbitrary values into v[0] to v[4] cout << "Five values stored in a vector are written to cout:" << endl; for (i = 0; i < 5; i++) cout << v[i] << " "; // print values to cout cout << endl; // of course you can also use iterators // define an iterator to the first vector element vector<int>::iterator first = v.begin(); // define an iterator past the last vector element vector<int>::iterator last = v.end(); cout << "Now the output loop works with iterators:" << endl; while (first != last) cout << *first++ << " "; // first the iterator is dereferenced, // then it is incremented } Exercise 4.1.2: #define __MINMAX_DEFINED // use STL's generic min and max templates #include "list.h" // include STL-list implementation
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

Stl-sol - The Standard Template Library Tutorial 184.437...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online