end

Syntax:

    #include <set>
    iterator end();
    const_iterator end() const;

The end() function returns an iterator just past the end of the multiset.

Note that before you can access the last element of the multiset using an iterator that you get from a call to end(), you'll have to decrement the iterator first.

For example, the following code uses end() to test an iterator that is used to traverse the elements of a multiset:

    multiset<int> ms;
    multiset<int>::iterator iter;
    int i;
 
    for (i = 1; i < 5; i++) {
        ms.insert(i);
        ms.insert(i*i);
        ms.insert(i-1);
    }
 
    cout << "ms is:" ;
    for (iter = ms.begin(); iter != ms.end(); iter++)
        cout << " " << *iter;
    cout << "." << endl;

The above code produces the following output:

ms is: 0 1 1 1 2 2 3 3 4 4 9 16.

end() runs in constant time.

Related Topics: begin, rbegin, rend