The difference between iostream and iostream.h

Source: Internet
Author: User

namespace, refers to the various visible ranges of identifiers. All identifiers in the C + + standard library are defined in a namespace called Std.
and is 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 functions defined in the global space, declared in the header file with the. h suffix, C + + standard in order to distinguish with C, and in order to correctly use the namespace, the header file does not use the suffix. h. Therefore, when used, the equivalent of calling library functions in C, the use of the global namespace, which is the earlier C + + implementation, when used, the header file does not define a global namespace, you must use namespace STD, so that the correct use of cout.
Use of Ps:namespace:
All identifiers in the C + + standard library are defined in a namespace called Std. 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;
The above procedure can be written
cout << Std::hex << 3.4 << Endl;
3, the most convenient is to use using namespace std;
For example:
#include
#include
#include
Using namespace Std
All identifiers defined in 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, the programmer is most likely to have the same name or name of the class as it is 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 functionality in pseudo-standard libraries that have been used for years, all in the global space. So there's a header file like this, one for compatibility with the previous C + + code, and one to support the new standard. The namespace std encapsulates the name of the standard library, and the standard library is generally not ". h" in order to distinguish it from previous header files.

The difference between iostream and iostream.h

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.