Re: Header Files HELP?!?!?!
Quote:
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