In contrast to the C language, C + + also uses the # include directive for header file inclusion, but unlike the new style header file of C + +, there is no suffix.
However, C + + header files can be added to the. h suffix, which adds no to the problem of namespaces.
In C language for a long time there is no concept of namespace, but in development often encounter such problems:
1, two chip manufacturers of a function name is the same, but the implementation of different functions, but the same function name will be error
2, received a colleague of a piece of code, but found that they have a lot of the same name of the function
Maybe C + + used the concept of command space to solve these problems, for example, if there are two people are the same name in the same room, shouting a name, two people do not know who is shouting, but if let two people in different rooms, then a shout 104 small a out, Then 105 of small B will not come out, which avoids the confusion. Classes and functions, as well as variables, can be considered components and placed in namespaces.
There are three ways to use namespaces:
1, using the use of the compiler instructions, with using namespace xxx;
2. Code that uses namespaces, such as #include<iostream>, that is used when using cout std::cout
3, including #include<iostream.h>, can be used directly cout
In a program, only the first method is generally used, and usually only the class or other parts that need to be used are declared, such as using Std::cout;
C + + Learning notes (1)