//C + + primary knowledge#include <iostream>//contains C + + standard header files//<iostream> and <iostream.h> format are not the same, the former has no suffix, in fact,//in your compiler include folder can be seen, the two are two files, open the file will find that the code is not the same. //The header file with the suffix. h C + + standard has been explicitly not supported, the earlier implementation of the standard library functionality is defined in the global space, declared in the header file with the. h suffix,//The C + + standard differs from C in order to correctly use namespaces and specifies that the header file does not use a suffix. h. Therefore,//1) When using <iostream.h>, the equivalent of calling library functions in C, using the global namespace, which is the early C + + implementation;//2) When using <iostream>, the header file does not have a global namespace defined, and namespace STD must be used so that cout can be used correctly. using namespaceStd//using standard definitions within the C + + standard namespace//①: in C + +, the name can be symbolic constants, variables, macros, functions, structures, enumerations, classes, objects, and so on. To avoid,//In the design of large-scale programs, and when programmers use a variety of C + + libraries, the names of these identifiers collide,//standard C + + introduces the keyword namespace (namespace/namespaces/namespace/name domain) to better control the scope of identifiers. //②:STD is a C + + standard namespace, and all identifiers in the C + + standard library are defined in STD, such as class iostream in the standard library, vector//are defined in the namespace, with a using declaration (using namespace STD) or a using indication (such as std::string,//std::vector<int>).//namespaces in the ③:c//there is only one global scope in the C language//all global identifiers in the C language share the same scope//There may be conflicts between identifiers//The concept of namespaces is presented in C + +//namespaces divide the global scope into different parts//identifiers in different namespaces can have the same name without conflicts//namespaces can be nested with each other//global scope is also called the default namespace//④:c++ the definition of a namespace://namespace name {...}//⑤:c++ use of namespaces://use the entire namespace: using namespace name;//using a variable in a namespace: using Name::variable;//use variables in the default namespace: :: Variable//By default, all identifiers in the default namespace can be used directly//⑥: Due to the concept of namespace, there are three options for using any identifier of the C + + standard library://1. Specify identifier directly. For example Std::ostream rather than ostream. The complete statement is as follows: Std::cout << std::hex << 3.4 << Std::endl;//2. Use using keyword. Using Std::cout; Using Std::endl; Using Std::cin; The above procedures can be written in cout << Std::hex << 3.4 << Endl;//3, the most convenient is to use using namespace Std; For example: using namespace std, so all identifiers defined within the namespace Std are valid (exposed). As if they were declared as global variables. //then the above statement can be written as follows: cout << hex << 3.4 << Endl;//because the standard library is very large, it is possible for programmers to choose the name or function name of a class that is the same as a name in the standard library. //so in order to avoid the name conflict caused by this situation, everything in the standard library is placed in the namespace Std. //but this poses a new problem. Countless original C + + code relies on features in the pseudo-standard library that have been used for years,//They are all in the global space. So there are <iostream.h> and <iostream> and so on such a header file,//one is to be compatible with the previous C + + code, one to support the new standard. //namespace STD Encapsulation is the name of the standard library, standard library in order to be different from the previous header file, generally do not add ". h"//Summary:// When using <iostream>, the header file does not have a global namespace defined, and namespace STD must be usedso that cout can be used correctly. //This is required if you do not introduce a using namespace Std. Std::cout. //The C + + standard differs from C in order to correctly use namespaces and specifies that the header file does not use a suffix. h. voidMain () {//cout standard output Terminal black screen-----c out//<< is the bitwise left shift operator in C//The C + + compiler has enhanced the functionality of the << operator (essentially operator overloading)cout <<"Hello C + +"<<Endl; intA =0; //entering data from the keyboard into a variableCIN >>A; cout<<"The data you entered is:"<< a <<Endl; System ("Pause");}
C + + C + + primary knowledge