The difference between #include <iostream> and #include<iostream.h>

Source: Internet
Author: User

                                 reprinted in Shangyang's blog: http://blog.sina.com.cn/s/blog_514b5f600100ayks.html                                    What's the difference between the two? First, 5 years ago we began to oppose the continuation of the. h symbol in a standard header file. It's not a good way to continue using outdated rules. In terms of functionality, a series of templated I/O is includedclass, instead of just supporting character streams. In addition, the C + + standard specification interface of the input and output stream has been improved in some subtle detail, so it is different from the interface and execution. Finally, the various components are based on the STL (Standard Templatelibraries, the standard Template Library), but the various components are declared to be global in shape. because of these substantial differences, you cannot confuse the use of these two libraries in a program. As a habit to use in new code, but if you're dealing with code that you've written in the past, in order to inherit it, you can keep the codeconsistency. /////////////////////////////indicates that you are using the label namespace, that is, at the beginning of the program should have such a sentenceusing namespace std, which follows the C + + standardthe C + + standard is not followed/////////////////////////////is the old C header file, corresponding to the char*-based string processing function;is the C + + header file that is packaged with STD, corresponding to the new STRNG class;is the STD version that corresponds to the old C header file. #include and #includeThe previous one is not in the C + + standard, the latter in the C + + standardThere are usually two situations we use, when there are output and input stream should be noted. Change to # include, add a using namespace std, or change cout to Std::cout,end to Std::endl, etc./////////////////////////////////////////////////////////////////////////////This problem involves namespaces, the following is a brief introduction to the benefits of namespaces://One.h char func (char); class String {...};//Somelib.h class String {...};if defined as described above, then these two header files cannot be included in the same program because the string class conflicts. A namespace is a method of encapsulating the name of a library, as if it were a neutral path in each libraryfence. For example://One.h namespace One {char func (char); class String {...};}//Somelib.h namespace Somelib {class String {...};}STD is a standard namespace defined by the C + + standard library, and you can remember both of these ways, and it takes a long time to understand//////////////////////////////////////////////////////////////////////////////for this question, one Ma Jianan teacher says:there's no < iostream.h > something like that---the standardization committee replaced it with < iostream > when simplifying the non-C standard header file. However, the use of < iostream.h > is not completely canceled, and many compilers support<iostream > and < iostream.h >, the situation, the Boss (Standardization committee) did have the necessary difficulties. in that year, when the standardization committee started rebuilding the new standard library, it encountered problems. In order to avoid the conflict between class name and function name, the namespace STD is introduced. But countless existing C + + code relies on work in pseudo-standard libraries that have been used for years can, for example, declare features in < iostream.h > and < complex.h > etc. header files. The existing software is not designed or upgraded for use with namespaces, and if the standard library is packaged with STD to prevent existing code from being used, the hand endThe younger brother (programmer) is not going to agree. in order to attract more people to join the Committee, the Standardization Commission decided to build a new header file name for the standard library that was packaged with Std. Remove the. h from the existing C + + header file name, so there's a lot of < iostream.h> and < iostream >Twins. For C header files, use the same method but add a C before each name, so C becomes. The old C + + header file is explicitly objected to by the official, but the old C header file is not (to maintain compatibility with C). In fact, the compiler manufacturer does not stop supporting the customer's existing software, so in the foreseeable future, the old C + + header files will beFor some time. If you can understand the use of the string header file, extrapolate, the other will almost be used. is the old C header file, corresponding to the char*-based string processing function;is the C + + header file that is packaged with STD, corresponding to the new STRNG class;is the STD version that corresponds to the old C header file. run away, get to the chase. If your compiler supports both < iostream > and < iostream.h, then use #include < iostream, and get the elements of the iostream library placed under the namespace Std; Include <iostream.h, the same elements that are placed in the global space. Acquiring an element in the global space causes a name conflict, and the design of the namespace is designed to avoid the occurrence of this name conflict. Also, when typing < iostream > ratio <iostream.h > Less two words, so I'll use < iostream > ^_^                                              transferred from: http://hi.baidu.com/laddie10/blog/item/079b1d4c32d7d8fcd62afc25.html                      the newly defined methods in C + + are namespaces, such as cout, which belong to the Std namespace if the Include header file is added with the. h, the default is using namespace otherwise you need to add the using namespace XXX For C that has beenthe definedmethods such as printf, without affecting theiostream.h is the header file that contains the input/output stream processing, iostream is nothingbut use iostream to add a noun space namespace#includeor a#includeusing namespace std;both. #include是C语言中比较通用的#includeusing namespace std;is more common in C + +. #include write, the functions inside are all global functions. No. h is now standard in C + + and is intended to enable C + + code to be used for porting and hybrid embedding without the limitation of the extension. h, avoiding additional processing and modification due to. hPlus, H is the use of C language, but also in C + + support this use, mainly to backward compatibility of C content, we usually try not to use this methodiostream is now a standard in C + +, designed to enable C + + code to be used for porting and blending without the extension. h limitations, avoiding additional processing and modification due to. h. Iostream contains the same basic functionality as the corresponding old header file, but the contents of the header file are in the namespace Std. (in the process of normalization, the details of some parts of the library have been modified, so the old header files and the entities in the new header file do not necessarily correspond exactly.) This header file should normally be used, andiostream.h are old-fashioned and may be eliminated later.     frequently ask questions about C + + header files in csdn and other technical forums. These questions are often raised by beginners who have just learned C + +. I asked a similar question when I was a rookie. now take a look at the following two include:#include//This is the standard header file after 1998 years of standardization#include//This is the standardization of the previous header filethe more fundamental difference is that iostream puts the components of the standard C + + library in a fame std namespace. The relative iostream.h put these standard components in the global space, and the old C standard library after standardization has beenhas been transformed. Using the former, you need to add a statement to the code: using namespace std;Take a look at these two header files//Standard library of standardized modified C, all components are placed in STD#include//standardize the C standard library in previous C + +#include//Look at this header file C standard library based on char* character processing function library#include//After standardization he became like this#include//But a lot of friends have seen this string handler library, and he contains the new string class#includeafter such a large-scale operation by the standard Committee, the compiled source files on the C + + compiler (bc3.0,bc5.0), which were produced before 98, may not be able to be compiled properly on compilers that support the new standard .. [Cause]Looking back at the standard library, this library covers a wide range of applications, and has been mentioned by many useful functions. It is because of this that the name and function name of class in the standard library and the class name or function in the library provided by the third partythe likelihood of name collisions is greatly increased. To avoid this problem, the standard Committee decided to place everything in the standard library in namespace Std. But this has led to a new problem. Many C + + program Generationscode relies on C + + "Quasi" standard libraries that have existed for many years (C + + has not been standardized to cause these occurrences), such as iosteam.h,complex.h, and so on. to address this emerging issue, the standardization Committee decided to design some new header filenames to be used for components that wear STD coats. Remove the. h of the C + + header file, so there is the iostream that appears earlier, and the same C header file doesThe same processing, plus a letter C in front of it to indicate that it is the head file of C (feeling a sense of racial discrimination). At the same time, the standardization Committee declared that some C + + header files would no longer be listed in the supported list, while the old C-textin order to meet the "compatibility of C" This ancient contract, will continue to live. However, those compiler vendors would not be able to overturn their customers ' old compilers (and would not have done so), so the old C + + header files still survived, and constantly disturbed the minds of the C + + recruits. Here's what most C + + development tools say about the organization state of the header file:1. old C + + header files such as iostream.h, although they were abandoned by the standardization committee, but because the major manufacturers for their own business interests will continue to survive, the contents of these header files will not be in namespace Std. 2. The new C + + header file, such as iostream, although provides the same functionality as the old header file, but his content is incorporated into the namespace STD, which effectively avoids the problem of name pollution. 3. The header files of standard C, such as stdio.h, continue to be supported, and the contents of such documents are not placed in Std. 4. C Function Library skills also have a corresponding version of the new C + +, from the name similar to Cstdio, the content of such a header file is also fortunate to wear an STD coat. In fact, standardization after the standard library changes are not only these, many of the standardized components are "tamplate". Among them is the elder character iostream. The problem with the standard library is not a single article, two articles can be said clearly. If you like to learn more about the standard library of C + +, you can look at Mr. Hou's C + + standard library.

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.