Mail Archives: djgpp/2002/09/19/09:45:12
Kim Seng <Query AT singnet DOT com DOT sg> wrote:
> Any example on this "std::" coding?
Before ANSI/ISO C++ Standard, all things in the standard library were
accessible just by their name, i.e. to access the standard output
stream you would write:
#include <iostream.h>
//...
cout << "blabla" << nl;
The Standard moved them all into a namespace called "std", so the
actual name of cout is now std::cout. It also changed the names of
the standardized header files to not have a ".h" at the end:
#include <iostream>
//...
std::cout << "blabla" << nl;
"using namespace std;" tells the compiler that you want all things in
the namespace "std" to become available in your program's space,
without those std:: prefixes.
The idea behind namespaces is to avoid conflicts of like-named things
from indepentant sources (the language standard, some vendor's
library, a third-party library, your own source code, ...). Like the
one between the function "count" provided by the C++ Standard Template
Library (STL for short) and your original example's variables called
"count", too. Because of namespaces, you can keep calling your
program's own variable "count", but still access the STL function as
std::count.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -