S60 5th Edition v0.9
Example Applications Guide

Iterator Example

1. About this Example
2. Description
3. Prerequisites
4. Design and Implementation
5. Results


1. About this Example

This example demonstrates the usage of Iterators.


2. Description

This example demonstrate two usage of iterators.

Usage 1: The usage1 function demonstrates how we can use an iterator for manipulating a container (vector). With the help of an iterartor we can find all the elements in the vector. After moving to a position assignment through an insert_iterator inserts the corresponding value into vector. If you assign through an insert_iterator several times, then you will be inserting several elements into the underlying container.

Usage 2 : An Output Iterator is a type that provides a mechanism for storing (but not necessarily accessing) a sequence of values. One example of Output Iterator is a tape: you can write a value to the current location and you can advance to the next location, but you cannot read values and you cannot back up or rewind. An ostream_iterator is an Output Iterator that performs formatted output of objects of type T to a particular ostream. The usage2 function copies the elements of an array to the standard output, separated by hyphens (-) and the elements of the same array to a file TEST.DAT, one per line.


3. Prerequisites

This examples requires a basic understanding of the Symbian framework and Carbide C++.

Also on hardware sis available in plugin needs to be installed.


4. Design and Implementation

The application is simple console based application. It has its own icon in installed folder and can be launched from the UI both in the emulator and in the device.


5. Results

OUTPUT:

Original Array: 0 1 2 3 4
Array after insertion : 0 100 200 2 3 4
Press a character to continue!

Example to demonstrate os_stream iterator
2 - 5 - 7 - 2 - 8 - 9 -
2 * 5 * 7 * 2 * 8 * 9 *
Press a character to exit!


© Nokia 2008

Back to top