Thread: to #include or not to #include

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    40

    to #include or not to #include

    When using functions that are in the standard library, I find that to use them I sometimes have to include the appropriote header, and sometimes I do not. e.g the strlen() function: I can use it without including the header it needs....

    can anyone tell me why?

    p.s. Just thought it would be fun to tell ya´ll, I´m in Mexico at an internet cafe, the cost is 10 pesos (aprx. $1 USD) per hour...not bad... and since I´m not near a compiler, I´m not sure for certain whether the strlen() will work without a header. sorry if it doesn´t.

    (using vc++ .net at home)
    Last edited by krygen; 12-24-2004 at 01:53 PM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    if you include a header, that header might in turn, include a header, which might include a header, etc, etc....<iostream> seems to include the necessary header for strlen


    i always include everything that i need whether or not i really need too...this will help ensure that a change in one header doesn't break your program (as far as includes go)
    Last edited by misplaced; 12-24-2004 at 01:51 PM.
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    who are you asking?

    edit: hmmmm..the previous post disappeared
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    sorry, for that, I didn't quite understand the previous post... that's why my reply was confusing.
    none...

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    It doesn't hurt to include something that another header file has already included, so just save yourself the trouble (not to mention everybody who reads your code) and include everything.

    edit: everything that you USE, that is...

  6. #6
    Registered User
    Join Date
    Jun 2004
    Posts
    40
    everything that you USE, that is...
    har har.

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >so just save yourself the trouble (not to mention everybody who reads your code) and include everything.
    Code:
    #ifndef EVERYTHING
    #define EVERYTHING
    
    #include <algorithm>
    #include <bitset>
    #include <cassert>
    #include <cctype>
    #include <cerrno>
    #include <cfloat>
    #include <ciso646>
    #include <climits>
    #include <clocale>
    #include <cmath>
    #include <csetjmp>
    #include <csignal>
    #include <cstdarg>
    #include <cstddef>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <cwchar>
    #include <cwctype>
    #include <complex>
    #include <deque>
    #include <exception>
    #include <fstream>
    #include <functional>
    #include <iomanip>
    #include <ios>
    #include <iosfwd>
    #include <iostream>
    #include <istream>
    #include <iterator>
    #include <limits>
    #include <list>
    #include <locale>
    #include <map>
    #include <memory>
    #include <new>
    #include <numeric>
    #include <ostream>
    #include <queue>
    #include <set>
    #include <sstream>
    #include <stack>
    #include <stdexcept>
    #include <strstream>
    #include <streambuf>
    #include <string>
    #include <typeinfo>
    #include <utility>
    #include <valarray>
    #include <vector>
    
    #endif
    Code:
    #include "everything.h"
    
    int main()
    {
      //...
    }
    >edit: everything that you USE, that is...
    Feh, party pooper.
    My best code is written with the delete key.

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I've been working with C too long... That file looks way too big and I don't even recognize half the files in there!

  9. #9
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    I think I'll use that header file in all of my examples from now on. I'll also be sure to use the most obscure solution I can imagine. That way you guys won't know what the hell I'm talking about most of the time.
    My best code is written with the delete key.

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Like we do now?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. debug assertion failed!
    By chintugavali in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 06:23 AM
  2. MFC include BS
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 10-31-2005, 12:44 PM
  3. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 01:21 PM
  4. #includes don't seem to be working
    By Inquirer in forum C++ Programming
    Replies: 12
    Last Post: 08-05-2002, 05:38 PM
  5. MFC Assertion Failure
    By maxthecat in forum Windows Programming
    Replies: 5
    Last Post: 08-01-2002, 09:58 AM