Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Newbie on headers

Last post 05-05-2008 2:37 AM by Mohammad Rastkar. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-17-2008 2:22 PM

    • cybrix101
    • Not Ranked
    • Joined on 04-17-2008
    • United Kingdom
    • New Member
    • Points 15

    Newbie on headers

    Hi Guys, my name is Richard and im new to the forum. I was wondering if someone could help me. I am starting to teach myself c++, using c++ for dummies. I am having problems compiling a code with headers. I have taken the code straight from the book and it still won't compile.
     
    This is the code:
     
    main.cpp
     
    #include <cstdlib>
    #include <iostream>
    #include <stdlib.h>
    #include <string>
    #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.cpp
     
    #include <string>
     
    using namespace std;
     
    string SafeCracker(int SafeID) {
    return "13-26-16";
    }
     
    safestuff.h
     
    string SafeCracker(int SafeID);
     
    has anyboy got any idea what i am doing wrong. any help would be appreciated.

    Thank you.

    Rich

    • Post Points: 15
  • 04-19-2008 6:26 PM In reply to

    Cool [H] Nice to see you!

    Hi Richard,

    Welcom to developerfusion! Left Hug

    => About your code :

    - You don't need to include 'stdlib.h', just enough to include 'cstdlib', since it's the newer version of 'stdlib.h'. But it's not a problem.

    - The problem is : you should include 'string' in 'safestuff.h', then add the following lines at the first of 'safestuff.h' :

    #include <string>

    using namespace std;

    Please note that, you should include all of required header files in each separate file of your project.

    - I don't have Time To waste The Time!
    • Post Points: 5
  • 05-04-2008 5:57 PM In reply to

    • legendario3
    • Not Ranked
    • Joined on 03-17-2008
    • United States
    • New Member
    • Points 15

    Re: Newbie on headers

    On detail toward the solution is that #include "safestuff.h"  should be added to safestuff.cpp file. 

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

    • Post Points: 10
  • 05-05-2008 2:37 AM In reply to

    Smiley Face [:)] In this case...

    Good point legendario3,

    But in this case, it's not required to include 'safestuff.h' in 'safestuff.cpp', since there is nothing in header file that is not defined in source file.

    - I don't have Time To waste The Time!
    • Post Points: 5
Page 1 of 1 (4 items)