Recency is subjective, of course...
IIRC, the standard became a Standard in 1998. A .pdf copy is available
somewhere on the ANSI web site for something like $15.00.
The notion of namespace std is somewhat less recent than the standard.
The notion of namespace is somewhat less recent than that.
To understand the "using namespace std" vs. "std::", you need to understand
the notion of namespaces. Very briefly, they are somewhat analogous to
"directories" in a filesystem. You can put portions of your code into their
own namespaces, like so:
void foo( );
void foo( );
We've now defined two functions named "foo." The first is
my_namespace::foo( ), the second is your_namespace::foo( ).
This is useful, for example, if you and I are working on a large project
where we are concerned about having each of us write functions that conflict
with each other. If we decide beforehand that everything I write will go in
my_namespace::, and everything you write will go in your_namespace::, then
we can write our code farely freely without having to worry that we'll
produce a conflict.
In this spirit of cooperation, the C++ Standards committee decided to put
the entire Standard C++ Library into namespace std. This is why you need to
specify "which" cout you want.
There are three ways to specify which cout you want. The first is to use
std::cout. The second is to place a "using namespace std" before your first
reference to cout. The final is to place a "using std::cout" before your
first reference to cout.
The first approach does not alter what is visible in the current scope,
while the second two will. The "using namespace..." approach takes
*everything* that is currently defined in the specified namespace, and makes
it visible in the current scope. The "using std::cout" takes only std::cout
and makes it visible in the current scope.
The approach that you take is largely a matter of personal preference,
style, etc. I prefer to never *ever* use the "using namespace" approach,
because it can have unexpected results. Do a groups.google.com search on
"using namespace" and you'll likely find tons of reading material on the
This is specified by the ISO C++ Standard (aka ANSI C++). AFAIK, no
compiler is yet 100% compliant with the Standard. However, any
recently-released compiler ought to have at *least* this feature.
- Early Ehlinger - CEO - www.ResPower.com - 866-737-7697
- 500+ GHz Self-Service Super-Computer from $0.50/GHz*Hr
- (yes, five hundred gigahertz. point-five terahertz.)
[ See http://www.yqcomputer.com/
[ comp.lang.c++.moderated. First time posters: Do this! ]