Newbie question

This is a discussion on Newbie question within the C++ Programming forums, part of the General Programming Boards category; What are header files?...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    36

    Newbie question

    What are header files?

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Files you include in your program. They have functions and stuff....

    Code:
    #include <iostream>  //<-- Thats a header file
    
    int main()
    {
    
        std::cout << "Llammas smell pretty";
    
        return 0;
    
    }

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >What are header files?
    Thingies (technical term) that declare names so that you can use them and compile the code before linking with the corresponding library. Without header files you would need to declare everything manually or you would get compilation errors. Technically (which is why I used the technical term ) headers need not be files, so calling them header files is somewhat of a misnomer.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    36
    by the way, vicious,, why u have std:: before the cout. What does that do?

  5. #5
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Quote Originally Posted by Sridar
    by the way, vicious,, why u have std:: before the cout. What does that do?
    instead of going
    Code:
    using namespace std;
    at the start, you can just go std:: in front of cout, cin, etc

    DW

  6. #6
    Teenage Mutant Ninja Nerd MMD_Lynx's Avatar
    Join Date
    Aug 2004
    Posts
    65
    heh...i never use std namespace or std:: and I have no trouble. in fact, when i do using namespace std;, i get an error. im using Borland 5.02
    Stupid people are useful. You can make them do all the mindless tasks you are too lazy to do yourself.

    Sphynx cats are just bald and wrinkly, like old people, and we don't reject them.

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    I"m using Borland 6, and I'm the same way. I can use non std, std::, using namespace std;

    All of them work just fine. I don't do console apps very offten, so I don't know too much on this subject. I would assume that Borland includes it some where already?

    DW

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >im using Borland 5.02
    Get a newer compiler.
    My best code is written with the delete key.

  9. #9
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    More about headers...

    There are about 50 headers in standard C++. You include them if you want to use the particular functions / functionality of a header.

    If you need to calculate a square root, you can use sqrt() if you #include <cmath>. If you need to work with time and dates, then #include <ctime>.

    Your compiler will probably have additional headers in addition to those required by the language standard. For example, <windows>.

    You can write your own header files (and an associated cpp file). This can be done to better organize a large program, or to make it easier to re-use your functions in another program.

  10. #10
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    I used to work with Borland. Only I was unfortunate enough to be stuck with version 3.1 which was 16-bit only. When I started hitting the memory limits it was either learn protected mode or switch to a new compiler that did the job for me. Guess which I choose.

    You might want to eventually switch to a different compiler because Borland is a bit on the proprietary side. Namely they're known to have commands specific to their compiler only which makes porting a headache.

    Ah header files. So much fun. I found I can store classes along with their code in a header file and not worry about having a separate file for the code. That is probably bad programming practice so I'll probably stop doing it... eventually.
    Last edited by Frobozz; 09-07-2004 at 03:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stupid Newbie question
    By TimL in forum C++ Programming
    Replies: 4
    Last Post: 07-22-2008, 05:43 AM
  2. C prog newbie question
    By Draginzuzu in forum C Programming
    Replies: 1
    Last Post: 02-03-2003, 06:45 PM
  3. a stupid question from a newbie
    By newcomer in forum C++ Programming
    Replies: 4
    Last Post: 01-11-2003, 04:38 PM
  4. confusion with integers (newbie question)
    By imortal in forum C Programming
    Replies: 7
    Last Post: 12-06-2002, 04:09 PM
  5. newbie class templates question
    By daysleeper in forum C++ Programming
    Replies: 2
    Last Post: 09-18-2001, 10:50 AM

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