2

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?

Niall
  • 28,969
  • 9
  • 96
  • 135
BVBC
  • 345
  • 2
  • 4
  • 11

2 Answers2

9

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.

Niall
  • 28,969
  • 9
  • 96
  • 135
Mohit Jain
  • 29,859
  • 8
  • 70
  • 95
1

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.

Violet Giraffe
  • 31,078
  • 43
  • 182
  • 317