Introduction
Introduction
– fred.FillArray(-2); fred.PrintArray();
– suzie.FillArray(3.25);
suzie.PrintArray();
– sam.FillArray(); sam.PrintArray();
– }
test output
– -2 -2 -2
– 3.25 3.25 3.25 3.25 3.25
– 2 2 2 2 2 2 2 2 2 2
STL General Concepts
●
Namespace std
●
(covered before)
– std::cout << std::hex << 127 <<
std::endl;
– or
– using std::cout;
– using std::endl;
– cout << std::hex << 127 << endl;
– or
– using namespace std;
– cout << hex << 127 << endl;
STL General Concepts
cont.
●
Header files
●
In addition to the standard ones:
– #include <iostream>
●
There is normally a special include
for each use of a STL template.
– #include <string>
– #include <vector>
– #include <stack>
●
(more specifics as we describe STL
components)
STL
Components
●
Containers
– Manage collections of objects of a
certain kind.
●
Iterators
– Used to step through the elements of
collections of objects.
– Small but common interface for an
arbitrary container type.
●
Algorithms
– Used to process elements of collections
container iterator
iterator
algorithm container
container iterator
STL
Sequence Containers
●
Ordered Collections.
●
Every element has a certain position.
●
Position independent of the value of
the element.
●
Position depends on order and place
of insertion.
– Vector
– Deque
– List
STL
Sequence Containers
Vector
Deque
List
STL
Associative Containers
●
Sorted Collection.
●
Actual position of an element
depends on its value due to certain
sorting criterion.
●
Order of insertion doesn't matter.
– Set
– Multiset
– Map
– Multimap
STL
Associative Containers
Set/Multiset
Map/Multimap
STL Iterators
– An object that can “iterate” over
elements. May be all or part of a STL
container.
– An iterator represents a certain
position in a container.
– Operator *
●
Returns the element of the actual
position.
– Operator ++
●
Lets the iterator step forward to the next
element.
●
Most iterators also allow stepping
backwards by using operator - -
(cont.)
●
Operator == and !=
●
Returns whether two iterators represent
the same position.
– Operator =
●
Assigns an iterator (the position of the
element to which it refers)
Iterator related member
functions
●
begin( )
– returns an interator that represents
the beginning of the elements in the
container.
●
end( )
– returns an iterator that represents the
end of the elements in the container.
– The end position is behind the last
element.
begin ( ) end ( )