1. The namespace is used to solve the variable with the same name in different files.
For example, if you add using namespace STD;
The STD namespace does not need to add STD.
The header file iostream. H is designed to be compatible with C. C does not have the namespace concept at all, so you do not need to add using namespace STD;
In a popular way, there are many classes in a school. When I am looking for a student on the first day, what kind of class is I looking?
Using namespace: one-to-one class;
When looking for all the students in the top one class, you do not need to enter the top one class: No. 1.
You do not need to write
Using Class 1: 1;
Using: Class 2;
You can simply write it to No. 1.
Note that manyProgramThe user will not use using namespace STD; because many variables are defined in the standard namespace STD, they will be repeated with their own variables accidentally, so what can be used is added before:
Using STD: CIN;
Using STD: cout;
Using STD: Endl;
You can.
2. Cooperative Development
In fact, this is still very useful, especially in the development of team cooperation, for example, if you share the module with everyone, a writes a class W, B Also wrote a class W, but since there was no good communication before, their class names were all the same at last. When they were integrated, there was a conflict during the call. If the namespace is used, it is easy to do. During the call, you only need to say that the class W that calls a or the class W that calls B solves the problem.
For example, namespace A {class W {...};}
Namespace B {class W {...};}
When used:
A: w aw // generate the W object written by
Aw. Get ().....
B: w bw // generate the W object written by B
Bw. Get ()....
In this way, we will differentiate who is the class.