Thread: Using c++ standards

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    Using c++ standards

    Just wondering what are the advantages of using the ansi standards in coding. I currently use #include <iostream.h> whereas ansi standards use #include <iostream>. Which is the correct approach when programming?

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    well, a couple years back, ansi said that .h was no longer to be used in C++ code, but i still stick with .h. its a matter of your coding style. i use the .h because things like the STL are clearly seperated from the headers, and i dont remember if the headers are C or C++ . im sure other people think differently.

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    So it doesn't really matter what style of coding you use? I don't really want to be coding in this way, if the ansi standard will soon become the "proper" way to code, or the most popular.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    well, from what i see, the most popular way is using .h, but it seems like no .h is the "proper" way to do it. it doesnt make sense to me whatsoever as to why ansi would change that/.

  5. #5
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    From Chapter 3.2 of The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis:
    The use of namespace std for all identifiers of the C++ standard library was introduced during the standardization process. This change is not backward compatible to old header files, in which identifiers of the C++ standard library are declared in the global scope. In addition, some interfaces of classes changed during the standardization process (however, the goal was to stay backward compatible if possible). So, a new style for the names of standard header files was introduced. This allows vendors to stay backward compatible by providing the old header files.
    The definition of new names for the standard header files was a good opportunity to standardize the extensions of header files. Previously, several extensions for header files were used; for example, .h, .hpp, .hxx. However, the new standard extension for header files might be a surprise: Standard headers no longer have extensions. Hence, include statements for standard header files look like this:
    #include <iostream>
    #include <string>
    This also applies to header files assumed from the C standard. C header files now have the new prefix c instead of the old extension .h:
    #include <cstdlib> // was: <stdlib.h>
    #include <cstring> // was: <string.h>
    Inside these header files, all identifiers are declared in namespace std.
    One advantage of this naming scheme is that you can distinguish the old string header for char* C functions from the new string header for the standard C++ class string:
    #include <string> // C++ class string
    #include <cstring> // char* functions from C
    Note that the new naming scheme of header files does not necessarily mean that the file names of standard header files have no extensions from the point of view of the operating system. How include statements for standard header files are handled is implementation defined. C++ systems might add an extension or even use built-in declarations without reading a file. However, in practice, most systems simply include the header from a file that has exactly the same name that is used in the include statement. So, in most systems, C++ standard header files simply have no extension. Note that this requirement for no extension applies only to standard header files. In general, it is still a good idea to use a certain extension for your own header files to help identify them in a file system.
    To maintain compatibility with C, the "old" standard C header files are still available. So, if necessary you can still use, for example,
    #include <stdlib.h>
    In this case, the identifiers are declared in both the global scope and in namespace std. In fact, these headers behave as if they declare all identifiers in namespace std followed by an explicit using declaration.
    For the C++ header files in the "old" format, such as <iostream.h>, there is no specification in the standard (this changed more than once during the standardization process). Hence, they are not supported. In practice, most vendors will probably provide them to enable backward compatibility. Note that there were more changes in the headers than just the introduction of namespace std. So in general you should either use the old names of header files or switch to the new standardized names.
    Forgive any typos, make of this what you will.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question - linux - gcc - c standards
    By AMAMH in forum C Programming
    Replies: 12
    Last Post: 12-03-2009, 02:49 AM
  2. C standards question
    By jim mcnamara in forum C Programming
    Replies: 7
    Last Post: 09-14-2007, 02:59 PM
  3. New standards
    By swgh in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-14-2006, 02:53 AM
  4. Standards
    By Brain Cell in forum C Programming
    Replies: 23
    Last Post: 07-01-2004, 06:22 AM
  5. Keeping up with newest standards
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2002, 08:06 AM