Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example Analysis of the header File with the suffix .h of C++

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains the "example analysis of the header file with the suffix .h of C++". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Now please follow the editor's train of thought slowly and deeply. Let's study and learn "C++ 's suffix .h header file example analysis"!

The C++ standard for the header file with the suffix .h has been clearly not supported. Earlier implementations defined the function of the standard library in the global space and declared it in the header file with the .h suffix. The C++ standard stipulates that the suffix .h is not used in the header file in order to distinguish it from C and to use the namespace correctly.

Therefore, when used, it is equivalent to calling the library function in c, using the global namespace, the early C++ implementation; when used, the header file does not define a global namespace, and you must use namespace std; in order to use cout correctly.

Generally, an old C++ code library file with an ".h" extension, such as iostream.h, has a corresponding one without a ".h" extension in the standard library after the new standard. In addition to many improvements of the latter, there is also a point that the latter's things are stuffed into the "std" namespace.

The problem is that C++ should be compatible with C's standard library, and C's standard library also happens to have a header file called "string.h", which contains some commonly used C string processing functions, such as strcmp mentioned by the landlord.

This header file has nothing to do with C++ 's string class, so it is not an "upgraded version", they are two header files that have nothing to do with each other.

To achieve the goal of the landlord, such as at the same time:

Void func () {using namespace alex;//using directive using chris::love;//uisng declares love (); / / chirs::love (); alex::love (); / / must be used}

Because the standard library is very large, programmers are likely to choose the name of a class or function that is the same as one of the names in the standard library. So to avoid name conflicts caused by this situation, everything in the standard library is placed in the namespace std. But it creates a new problem. Countless original C++ codes rely on functions in the pseudo-standard library that have been used for many years, all in the global space.

So there are header files like, and so on, one to be compatible with the previous C++ code, and the other to support the new standard. All the landmarks in the C++ standard library are defined in a namespace std, and iostream is also the header file in the standard library. If you look at the include directory, you will find two header files, iostream.h and iostream, of which iostream.h is the previous library of C++, and iostream is the library in the namespace std, so when you include the header file and want to use the markers in the header file, there are two ways.

Thank you for your reading. The above is the content of "example analysis of the header file with the suffix .h of C++". After the study of this article, I believe you have a deeper understanding of the example analysis of the header file with the suffix .h of C++. Specific use also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report