CIS-255 Home http://www.c-jump.com/bcc/c255c/c255syllabus.htm
A simple mechanism for organizing large programs
Named scopes with no other functionality - these are called namespaces.
Good for avoiding collisions and making name connections more explicit.
|
|
Classes and functions must be declared in a namespace to be placed inside the namespace
Definitions can use the :: qualifier or be placed inside a namespace.
using declarations provide local aliases for qualified names (this imports symbols):
using mylibrary::IntStack; // using declaration
IntStack st;
Can also import everything at once:
using namespace mylibrary; // using directive
Namespaces may have using declarations:
namespace mylibrary {
using otherlib::IntStack; // using declaration
//...
}
All C++ standard library stuff is defined inside the std namespace.
Saying
#include <iostream>
using namespace std;
means that C++ will give you everything from std without requiring std:: qualification.
For example, cout is really the std::cout:
#include <iostream>
int main()
{
using namespace std;
cout << "hello";
return 0;
}
Other than I/O, what else is there in std namespace?
Lots, and all organized using C++ templates!