Results 1 to 21 of 21

Thread: Header Files HELP?!?!?!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

    Header Files HELP?!?!?!

    Why won't my code recognize a header file? It won't compile for some reason? Please Help. The code is written right from the C++ for Dummies book.

    main.cpp

    #include <iostream>
    #include <stdlib.h>
    #include "safestuff.h"
    using namespace std;
    int main(int argc, char *argv[])
    {
    cout << "Surprise, surprise!" << endl;
    cout << "The combination is (once again)" << endl;
    cout << SafeCracker(12) << endl;

    system("PAUSE");
    return 0;
    }

    safestuff.h

    #include <safestuff.h>
    string SafeCracker(int SafeID);

    safestuff.cpp

    #include <string>
    #include <safestuff.h>
    string SafeCracker(int SafeID) {
    return "13-26-16";
    }

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: Header Files HELP?!?!?!

    Originally posted by Esham
    Why won't my code recognize a header file? It won't compile for some reason? Please Help. The code is written right from the C++ for Dummies book.

    main.cpp

    #include <iostream>
    #include <stdlib.h>
    #include "safestuff.h"
    using namespace std;
    int main(int argc, char *argv[])
    {
    cout << "Surprise, surprise!" << endl;
    cout << "The combination is (once again)" << endl;
    cout << SafeCracker(12) << endl;

    system("PAUSE");
    return 0;
    }

    safestuff.h

    #include <safestuff.h>
    string SafeCracker(int SafeID);

    safestuff.cpp

    #include <string>
    #include <safestuff.h>
    string SafeCracker(int SafeID) {
    return "13-26-16";
    }

    At least the line I have higlighted should not be there...no need to include the file you are all ready working on. An other good idea is to use guards, so the header file won't be included twice. That might be a problem here too, since you are including it two times. Change the whole code in safestuff.h to this:

    Code:
    #ifndef _SAFESTUFF_H
    #define _SAFESTUFF_H
    
    string SafeCracker(int SafeID);
    
    #endif 

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    In safestuff.cpp, you have the wrong delimiters for safestuff.h's name.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190
    Originally posted by CornedBee
    In safestuff.cpp, you have the wrong delimiters for safestuff.h's name.

    Ohhhh.......didn't notice that it was more errors..

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    Originally posted by CornedBee
    In safestuff.cpp, you have the wrong delimiters for safestuff.h's name.
    What should the delimeters be? My compiler won't get past the main.cpp. Here is the error report. Any Ideas??

    Line 3 | File BLAH BLAH | In file included from main.cpp

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What compiler do you use?

    It should be

    #include "safestuff.h"
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    I tried that and it still doesn't work.

    How do I know what compiler I'm using? In the compiler options it just says "Default compiler".

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What IDE, then?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    Originally posted by CornedBee
    What IDE, then?
    DEV-C++ 4.9.9.0

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Ok, now tell me what really was there instead of the BLAH BLAH.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    c:\misc\CPP\FirstProject\main.cpp

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    Maybe this will help. I got it by typing in "cl /?" on the command prompt.

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    No, Dev-C++ uses GCC, not MSC.

    I don't believe that was the whole error message, though.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    Maybe this will help. I got it by typing in "cl /?" on the command prompt.

    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    Originally posted by CornedBee
    No, Dev-C++ uses GCC, not MSC.

    I don't believe that was the whole error message, though.
    Here is everything I get after I compile (or try to compile).


  16. #16
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Go to the tab "compile log" and tell me what it says there.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155

  18. #18
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You have a syntax error inside the header. The line3 thing only shows from where the header with the error was included.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    Here is what my header file looks like. What is the syntax error?

    Code:
    #ifndef _SAFESTUFF_H
    #define _SAFESTUFF_H
    
    string SafeCracker(int SafeID);
    
    #endif

  20. #20
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Code:
    #ifndef _SAFESTUFF_H
    #define _SAFESTUFF_H
    
    #include <string>
    
    std::string SafeCracker(int SafeID);
    
    #endif
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2004
    Posts
    155
    So realy all I had to do was include:

    using namespace std;

    in all the files. What a PIMA! I wish the book would say that somewhere!!!! Thanks for all your help!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width