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
  • 30,036
  • 10
  • 99
  • 142
BVBC
  • 375
  • 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
  • 30,036
  • 10
  • 99
  • 142
Mohit Jain
  • 30,259
  • 8
  • 73
  • 100
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
  • 32,368
  • 48
  • 194
  • 335