confusing thing abnout headers or wutrever

This is a discussion on confusing thing abnout headers or wutrever within the C++ Programming forums, part of the General Programming Boards category; ok you know those headers #include <iostream> well in the things you guys post the source to i barely ever ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    196

    confusing thing abnout headers or wutrever

    ok you know those headers
    #include <iostream>


    well in the things you guys post the source to i barely ever see that so wuts everything i can put there im really cunfuzzlefied

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    You need to put each header that contains the standard library code you want to access. You only need to put the headers that contain the code you want to access. So whenever you use something in your code, you need to make sure you know which header it is from and include that header.

    So if you use cout, you need to include <iostream>. If you use string, you need to include <string>. If you use int, you don't need to include anything extra, since int is part of the language. If you use rand(), you need to include <cstdlib>. And so on. Your reference book or website should tell you which header is required (if any) for each thing you use.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    196
    thanks i can study them now but i have a question why do they make headers why dont they just put all the libs in the language
    and if im making a big game and i cant keep track coudnt i just write all the headers

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    It is better to keep track of what you are using and what you aren't. It is best to understand what you are using and what you aren't. If you just include all the headers, your code will be sloppier and harder to follow, but it should still work.

    The are several reasons that things are broken down into headers. One is that it separates interfaces from implementation (a good thing in program design). Another is that it speeds up compile times. If all the standard library code was automatically included, that would take the compiler a lot longer to find the things you are trying to use.

  6. #6
    Registered User
    Join Date
    Mar 2005
    Posts
    140
    Quote Originally Posted by lilhawk2892
    why dont they just put all the libs in the language
    -different libraires were written by different people at different points in time

    -logically organize similar routines into maintainable files

    -It would greatly and pointlessly increase compile time to include every librairy

    There would probably be little harm in you including all the headers you are familiar with in all of the source files you write. It might make your code misleading to someone else, and increase compile time. It shouldn't be that difficult to only include a header when you need it.

    Edit: Beat by Daved
    Last edited by spydoor; 09-21-2005 at 10:14 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM

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