Different includes

This is a discussion on Different includes within the C++ Programming forums, part of the General Programming Boards category; This might seem like a question I shouldn't be asking, but I've seen different variations of #include. Sometimes you include ...

  1. #1
    myNegReal
    Join Date
    Jun 2005
    Posts
    100

    Different includes

    This might seem like a question I shouldn't be asking, but I've seen different variations of #include. Sometimes you include .h and sometimes you don't. I've read recently that in C++ you don't put .h and in C you do. But in source code I look at and when I first tried a bit of C++ a few years ago (I stopped for years, I was working with Java, so I didn't keep up to date with C++), you'd have .h in #include. For example:
    Code:
    #include <iostream.h>
    // Now it's
    #include <iostream>
    But when I look at some source code written pretty recently it has .h in it, but when I try to compile with .h it gives me an error. Why don't you put .h and when would be a time you do?

    Also, I've seen #include written with <> or "". Usually when I see it written with quotes it's a user-created header file. Is that when you use it? And <> for built in header files? Like:
    Code:
    #include <iostream>
    #include "myHeaderFile"
    Or do they distinguish something else?

    And now you have to use namespaces like
    Code:
    #include <iostream>
    using namespace std;
    // or instead of the using namespace line, 
    // when calling a function like cout put the namespace name
    // in front like a class
    std::cout<<"Text";
    I never had to do that. I'm guessing C++ has changed since the last time I used it? I know about namespaces, are they new, and C++ changed like that? Or where they always in the C++ language, you just never needed to define the namespace?

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    the .h #includes are usually depreciated headers
    or your own personal header file, all of the now standard
    header file do not require the .h , alot of the old c
    header file that you may still choose to use in
    c++ require the .h such as <ctime.h>

    and as far as i know the namespace thing has been around for
    a while al lit does is let you nto have to type std::
    infront of alot of stuff.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479

    i agree

    I agree with the above comment.
    i do not use .h any more for iostream, the only ones I use it for is
    windows.h and conio.h. The use of .h is mainly surrounding the C langugage, when it was introduced, C++ did away with all the old C jargon like that, and having to put std:: in a cout and namespace function. you can still use these features, but I personally do the other! It does make programming easyer, and reduces errors such as syntax and parse errors on compilation

  4. #4
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Yeah seems like they basicly just revamped their code when they did away with .h's, and put code in namespaces for the benefits of doing that: having different versions of code with the same variable/function/etc. names, makes it easy to have alternate data that almost does the same thing (and imho I wouldnt use 'using namespace std' just because I like the extra clarification of std::, makes my attention easier when spotting my personal code and not the iostream code.)
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    myNegReal
    Join Date
    Jun 2005
    Posts
    100
    What exactly is a depreciated header? Also I understand the namespaces, I just never seen them used before. I guess a few years ago when I tried C++ it was a mixed coding of C and C++ and the compiler still compiled it fine.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    "Deprecated" means that something is marked as "possibly being removed in the near future. Use is highly discouraged."
    It is good to note that the C++ standard never contained the .h versions of the C++ headers in the first place, so it never deprecated them. As far as the standard is concerned, they simply don't exist. However, the standard does contain and deprecate the old style C headers (stdio.h) in favour of the new style (cstdio).
    Compilers that originally contained the old C++ headers have deprecated them in their own right: GCC deprecated them in the 3.x series. MS VC++ did so in version 7 (.Net 2002), and actually removed them in 7.1 (.Net 2003).
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,340

  8. #8
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    You can call your own header files with any extension. It is popular in some places to have C++ headers end with .hpp. You can include anything you like (the preprocessor simply copies and pastes the contents of the file, presuming it can find it).

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    A header file with angle brackets, like this,
    Code:
    #include <hippo>
    usually makes the compiler look in the include directory, and if it isn't there, creates an error. Double quoted includes, one the other hand, make the compiler look in the current directory first, and then the include directory. So for built-in headers you use angle brackets, and for your own header files you use double quotes.

  10. #10
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    For angle bracket includes the compiler looks on a defined set of paths (which can be altered easily) where as quoted includes the compiler looks based on the current directory (so you can have relative paths in the header include name).

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  11. #11
    myNegReal
    Join Date
    Jun 2005
    Posts
    100
    Ah I see, thanks guys.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Makefile and includes
    By Lang in forum C Programming
    Replies: 4
    Last Post: 03-18-2008, 03:29 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Why are using declarations passed over but not includes
    By indigo0086 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2006, 10:54 AM
  4. Circular includes
    By ventolin in forum C++ Programming
    Replies: 2
    Last Post: 05-23-2004, 05:43 PM
  5. #includes
    By RedLenses in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2002, 02:59 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21