| ||||
| ||||
| (since C++11) |
Returns an iterator to the first element of the container.
If the container is empty, the returned iterator will be equal to end()
.
Parameters
(none).
Return value
Iterator to the first element.
Exceptions
(none) | (until C++11) |
noexcept specification: noexcept | (since C++11) |
Complexity
Constant.
Example
See also
returns an iterator to the end (public member function) |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <map> #include <string> #include <iostream> #include <iterator> int main() { std::map<std::string,std::string> a_map; a_map[ "Geely" ] = "Chinese" ; a_map[ "Peugeot" ] = "French" ; a_map[ "Mercedes" ] = "German" ; a_map[ "Toyota" ] = "Japanese" ; a_map[ "Ford" ] = "American" ; a_map[ "Fiat" ] = "Italian" ; for (auto it = a_map.cbegin(); it != std::next(a_map.cbegin(), 3); ++it) { std::cout << it->first << " : " << it->second << '\n' ; } } |
Output:
1 2 3 | Fiat : Italian Ford : American Geely : Chinese |
Please login to continue.