Like Tree2Likes
  • 1 Post By laserlight
  • 1 Post By rogster001

How do you make a header file

This is a discussion on How do you make a header file within the C++ Programming forums, part of the General Programming Boards category; How do you? I just can't seem to find how to create a header file and where I canchange the ...

  1. #1
    Registered User Inkinsarto's Avatar
    Join Date
    Apr 2013
    Posts
    34

    How do you make a header file

    How do you? I just can't seem to find how to create a header file and where I canchange the value of the variables. It sounds simple, but I hope someone has an answer.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    I'm not sure what you are asking about. Are you asking what is a typical layout of a header file, as in what it would contain? Or are you asking how to create a header file in say, your IDE? Or are you asking a specific question ("change the value of the variables") concerning a particular header file?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Inkinsarto's Avatar
    Join Date
    Apr 2013
    Posts
    34
    Let's say that all I want is to create a simple program with the variable x. And it equals 0. Is there a way that I could take this program and make it into a header file? Also allowing me to add and change values.(x + 1, x - 5, etc.)

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Quote Originally Posted by Inkinsarto
    Let's say that all I want is to create a simple program with the variable x. And it equals 0. Is there a way that I could take this program and make it into a header file? Also allowing me to add and change values.(x + 1, x - 5, etc.)
    Yes, you could use a header file here, but why would you? For a program like this, you might as well have everything go into a single main function in a source file. No header file required.

    Do you know how to forward declare functions? Do you know how to define classes? These are the more things that you should be thinking about placing in a header file.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User Inkinsarto's Avatar
    Join Date
    Apr 2013
    Posts
    34
    That is just an example. I actually wish to place many many variables and function in a file, then use it as a header.(This is to shorten my programs) How do I actually make a header. Is there some function I need to place or do I need to start a project as something else?

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    Well, what learning material are you using? At some point, it should be telling you how to write a header file, including why we use them and what should go into them. I already gave you a hint as to what would normally go into a header file in my previous post.
    dennis.cpp likes this.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User Inkinsarto's Avatar
    Join Date
    Apr 2013
    Posts
    34
    I am now begining Binary trees.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,717
    That does not say much though: the learning of binary trees is orthogonal to the learning of C++. My point is that you are asking something that should be explained by whatever you are using to learn C++, be it a formal introductory programming course, a book or an online tutorial. A programming forum is a right place to clarify whatever your learning material might teach about header files, but a wrong place to introduce them to you in depth.

    If you already have some idea of how to write a header file but want clarification, show us an example of what you have in mind and request for comment.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,425
    if you want to see a header file you only need to go into your compiler's directory will contain lots you can look at - and get an idea about the things they contain, thats what i did to start with, but then now you have an internet connection - there must be millions of simple examples you can find. I think you are perhaps confusing writing a header with breaking a program into seperate source files, learn about both these things anyway.
    dennis.cpp likes this.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  10. #10
    Registered User Inkinsarto's Avatar
    Join Date
    Apr 2013
    Posts
    34
    I have been researching the subject, and have found certain functions that allows one to create namespaces:
    Code:
    using namespace "name"
    {
      //functions
    }
    The only problem with this is that the file can only be accessed on the code. Is there a header that I can use that will allow me to create a program/code and then compile it; allowing me to access the file in another program.

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,593
    I think there is much confusing stemming from that you seem to be confused on what exactly these features are. I don't even understand what you are saying.
    The best advice I can give right now is to look up what namespaces are, what using namespace X does, and what files are and how to use them, and what headers are for.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,698
    I actually wish to place many many variables and function in a file, then use it as a header.(This is to shorten my programs)
    I know what this kind of header file looks like. I also know that making programs that depend on global variables a bunch are bad programs.

    Like laserlight says, you have more important things to learn. I'm also going to suggest you learn what scope is in C++, and use that knowledge as much as you can. Variable names should be made accessible in the smallest regions possible. This makes debugging easier, especially when it comes down to watching the effects of a particular variable, because you know where to look, and hopefully that region is a small place.

  13. #13
    Registered User Inkinsarto's Avatar
    Join Date
    Apr 2013
    Posts
    34
    Cool. And thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to make a Library file and header file in GCC?
    By mhrsolanki2020 in forum C Programming
    Replies: 16
    Last Post: 12-22-2012, 10:51 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. How to make my own header/library?
    By Ash1981 in forum C Programming
    Replies: 7
    Last Post: 12-31-2005, 07:01 PM
  4. Replies: 4
    Last Post: 12-14-2005, 01:21 PM
  5. I want to make a *.lib for my header file
    By tudehopet in forum C++ Programming
    Replies: 6
    Last Post: 05-18-2002, 04:14 AM

Tags for this Thread


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