Skip to content

Latest commit

 

History

History
26 lines (21 loc) · 692 Bytes

begin.md

File metadata and controls

26 lines (21 loc) · 692 Bytes

begin

Description : This function is used to return an iterator pointing to the first element of the map container. begin() function returns a bidirectional iterator to the first element of the container.

Example :

// Demonstrates begin() 
#include <iostream> 
#include <map> 
  
int main() { 
    // declaration of map container 
    std::map<char, int> mymap; 
    mymap['a'] = 1; 
    mymap['b'] = 2; 
    mymap['c'] = 3; 
  
    // using begin() to print map 
    for (auto it = mymap.begin(); it != mymap.end(); ++it) 
        std::cout << it->first << " = "
             << it->second << '\n'; 
    return 0; 
} 

Run Code