begin [C++ Reference]
Keywords: stl,list,begin
Date: 2009-02-02T11:07:32-0800

[[begin]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## begin

Syntax:

        #include <list>
        iterator begin();
        const_iterator begin() const;

The function begin() returns an iterator to the first element of the list. begin() should run in constant time.

For example, the following code uses begin() to initialize an iterator that is used to traverse a list:

         // Create a list of characters
         list<char> my_list;
         for( int i = 0; i < 10; i++ ) {
           my_list.push_front( i + 'a' );
         }

         // Display the list
         list<char>::iterator it;
         for( it = my_list.begin(); it != my_list.end(); ++it ) {
           cout << *it;
         }

Related Topics: end, rbegin, rend

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •