I'm reading The C++ Programming Language, 4th Edition (by Bjarne Stroustrup) about argument-dependent-lookup. Here is the quote (26.3.6, Overaggressive ADL):
Argument-dependent lookup (often referred to as ADL) is very useful to avoid verbosity (14.2.4). For example:
#include <iostream> int main() { std::cout << "Hello, world" << endl; // OK because of ADL }
Without argument-dependent lookup, the
endl
manipulator would not be found. As it is, the compiler notices that the first argument to<<
is anostream
defined instd
. Therefore, it looks forendl
instd
and finds it (in<iostream>
).
And here's the result produced by the compiler (C++11 mode):
prog.cpp: In function ‘int main()’:
prog.cpp:4:36: error: ‘endl’ was not declared in this scope
std::cout << "Hello, world" << endl;
^
Either this is a bug in the compiler or in the book. What does the standard say?
Update:
I need to clarify a bit. I know that the right answer is to use std::endl
. The question was about the text in the book. As Lachlan Easton already said, it is not just a typo. The whole paragraph is (probably) wrong. I can accept this kind of error if the book is by an other (lesser known) author, but I was (and still am) in doubt because it was written by Bjarne.