On Thu, 30 Sep 2004 19:38:40 +0100 John Lamb <J.D.Lamb@btinternet.com> wrote:
In practice there are two ways to use the namespace:
1. (java-style) Always qualify standard library functions with std:: as in
std::cout << "Hello." << std::endl
I prefer this style.
2. (C-style) Use the using directive to make the standard library available whenever you want it. The typical way to do this is to start a file
#include<iostream> using namespace std;
Then any standard library function becomes available globally without the std:: qualifier.
You can also make the standard library available locally, e.g.
double function( double x ){ // OK using namespace std; return x + sqrt( x ); }
double another_function( double x ){ // error - no function sqrt() in current scope. return x - sqrt( x ); } <snip> I'm glad your raised namespaces John. There are actually 3 ways to use namespaces. using std::cout; using std::cin; using std::endl;
Most C++ "experts" advise that "using namespace std" is not a good practice. The bottom line is when learning a new language, you should try to use the best practices to avoid getting into bad habits. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9