Thread: Preprocessor Directives

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    5

    Preprocessor Directives

    I have never really done this before but I am using the example found on the site. I encountered a problemand worked through it, but I am not sure what is going on and would appreciate some feedback.

    I have a program with a great deal of functions. Rather than having one large file of code I decided to split it up into groups.

    I started by creating a header file with a corresponding .cpp file of functions that do nothing but act as filters. I then compiled, linked, and ran the program. Everything worked great! I was actually kind of proud of myself.

    Armed with that success I went on to create another header file and corresponding .cpp file for what I called output functions. This is where I encountered a problem. The .cpp file for this group of functions kept returning errors that I have always seen associated with me not remembering to use a preprocessor directive. I eventually got it to compile and run but only when i added the ".h" after each directive.

    I am using Microsoft Visual C++ 6.0.

    Why did I just use the name of the library in the first file and I had to add the ".h" to the second? There are a few more break ups to the program I would like to do but wanted to get this answered first.

    Thank you for any assistance.
    Elliott

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Showing some of your code might be easier, or at least referring to the library you are talking about. I am guessing that in one file you could use <iostream> and in the other file you had to use <iostream.h>. Is that correct? If so, then you are probably missing the std namespace declaration in the one that didn't work.

    If that's not it, at the very least post the exact error message and the code it refers to.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    5
    Thanks for the advice. I went back and rewrote the code the way I had it to begin with and then added "using namespace std;". Everything worked fine. Thank you again.

    Elliott

Popular pages Recent additions subscribe to a feed