Namespace is the namespace of c ++. In order to solve the problem that naming is easy to repeat during programming, a namespace concept is proposed. The names of variables, functions, and classes in the same namespace cannot be repeated. These names can be repeated in different namespaces. For example:
Namespace n1
{
Int;
}
Namespace n2
{
Int;
}
It can be used as follows:
N2: a = 8;
N1: a = 8;
You can also declare that the namespace I want to use is n2:
Using namespace n2;
In this case, the default namespace is n2, which can be directly written:
A = 8;
Same as n2: a = 8;
And using namespace std;
Std in is the namespace used by standard library functions. Here we should first talk about the methods that contain library functions. The old method is:
# Include <stdio. h>
This is to be compatible with c. Without namespaces, he can directly call the library functions in it, for example:
Printf ("% d", 2 );
The new method is:
# Include <cstdio>
This is to better support classes, but namespace should be used for example:
Using namespace std;
Printf ("& d", 2 );
If you do not add using namespace std ;,
In the program, the effects of std: cout, std: cin, std: endl are the same.
If the compiler supports both <iostream> and
<Iostream. h>. If # include
<Iostream>, the elements of the iostream library placed under the namespace std are obtained;
If you use # include <iostream. h>, the same elements that are placed in the global space are obtained. All
An element obtained from a local space may cause a name conflict. The original intention of designing a namespace is to avoid such a name conflict.
Occurrence of word conflict.