Thread: Problem with #include

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640

    Problem with #include

    Hello,

    In my source i include a file tat holds all the includes and
    some functions and voids.
    Now when my header file named "test.h" has this:

    #include <iostream>

    void something()
    {
    cout << "Im printing something" << endl;
    }

    And i compile it with my source, Im getting error messages
    with the void in my header file that are pointing out that
    "#include <iostream>" isn't even being used in the header file
    I can use it in my source, but not in the header file???
    What am i doing wrong?

  2. #2
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Donīt really understand what you mean. From where I can se you are trying to compile a header file??? In c++ you cannot compile header files just source files.

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    you can't have code/functions in a header file, just definitions of things.
    Away.

  4. #4
    Microsoft. Who? MethodMan's Avatar
    Join Date
    Mar 2002
    Posts
    1,198
    So in test.cpp you will have a function

    Code:
    void print()
    {
      cout << "something" << endl;
    }
    and in test.h

    you just have the prototype of the print function so

    Code:
    void print();
    -MethodMan-

    Your Move:Life is a game, Play it; Life is a challenge, Meet it; Life is an opportunity, capture it.

    Homepage: http://www.freewebs.com/andy_moog/home.html

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    (this is my header file)

    #include <iostream>

    void bla()
    {
    cout << "bla"; // I can't do this!
    }

    void bla2()
    {
    printf("bla"); // But i can do this ?1
    }


    I'ts like it isnt using iostream in the functions in the header file

    (im not compiling the header file, im including it in my source)

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You need to have this line:
    Code:
    using namespace std;
    under #include <iostream>

    If not then each call to cout needs to read:
    Code:
    std::cout<<"words"<<endl;

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    DOH! Of course , sorry i forgot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with simple socket client/server program
    By spencer88 in forum C Programming
    Replies: 6
    Last Post: 05-05-2009, 11:05 PM
  2. debug assertion failed!
    By chintugavali in forum C Programming
    Replies: 4
    Last Post: 12-11-2007, 06:23 AM
  3. include problem
    By Strait in forum C++ Programming
    Replies: 4
    Last Post: 01-31-2005, 04:01 PM
  4. Read and write hanging
    By zee in forum C Programming
    Replies: 8
    Last Post: 08-03-2004, 11:19 PM
  5. help with finding lowest number entered
    By volk in forum C++ Programming
    Replies: 12
    Last Post: 03-22-2003, 01:21 PM