简体   繁体   中英

Where are the begin() and end() functions defined in C++?

In cppreference.com, it states that the begin() and end() functions are defined in the header file < iterator > . But I still can use the begin() and end() functions without including the < iterator > header. I wonder why? Is it because I use;

using namespace std;

So it is included?

Read from notes on the same page :

In addition to being included in <iterator> , std::begin is guaranteed to become available if any of the following headers are included: <array> , <deque> , <forward_list> , <list> , <map> , <regex> , <set> , <string> , <unordered_map> , <unordered_set> , and <vector> .

Apart from these list of headers, std::begin may get included from some other header also.

No, using namespace xxx doesn't include any header files. It only means that you can write begin() instead of std::begin() . The <iterator> header must be included through some other header that you did include into your .cpp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM