using namespace std;
instructs the compiler to search for undecorated names (ie, ones without ::
s) in std
as well as the root namespace. Now, the tolower
you're looking at is part of the C library, and thus in the root namespace, which is always on the search path, but can also be explicitly referenced with ::tolower
.
There's also a std::tolower
however, which takes two parameters. When you have using namespace std;
and attempt to use tolower
, the compiler doesn't know which one you mean, and so it' becomes an error.
As such, you need to use ::tolower
to specify you want the one in the root namespace.
This, incidentally, is an example why using namespace std;
can be a bad idea. There's enough random stuff in std
(and C++0x adds more!) that it's quite likely that name collisions can occur. I would recommend you not use using namespace std;
, and rather explicitly use, e.g. using std::transform;
specifically.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…