|
-
Nov 11th, 2004, 05:10 PM
#1
Thread Starter
Addicted Member
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";
}
-
Nov 11th, 2004, 06:38 PM
#2
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
-
Nov 12th, 2004, 03:35 AM
#3
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.
-
Nov 12th, 2004, 08:16 AM
#4
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..
-
Nov 12th, 2004, 08:37 AM
#5
Thread Starter
Addicted Member
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
-
Nov 12th, 2004, 10:36 AM
#6
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.
-
Nov 12th, 2004, 10:41 AM
#7
Thread Starter
Addicted Member
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".
-
Nov 12th, 2004, 10:47 AM
#8
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.
-
Nov 12th, 2004, 10:57 AM
#9
Thread Starter
Addicted Member
Originally posted by CornedBee
What IDE, then?
DEV-C++ 4.9.9.0
-
Nov 12th, 2004, 11:05 AM
#10
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.
-
Nov 12th, 2004, 11:17 AM
#11
Thread Starter
Addicted Member
c:\misc\CPP\FirstProject\main.cpp
-
Nov 12th, 2004, 11:22 AM
#12
Thread Starter
Addicted Member
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
-
Nov 12th, 2004, 11:28 AM
#13
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.
-
Nov 12th, 2004, 11:28 AM
#14
Thread Starter
Addicted Member
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
-
Nov 12th, 2004, 02:01 PM
#15
Thread Starter
Addicted Member
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).
-
Nov 12th, 2004, 03:01 PM
#16
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.
-
Nov 12th, 2004, 03:11 PM
#17
Thread Starter
Addicted Member
-
Nov 12th, 2004, 03:21 PM
#18
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.
-
Nov 12th, 2004, 03:25 PM
#19
Thread Starter
Addicted Member
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
-
Nov 12th, 2004, 03:31 PM
#20
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.
-
Nov 12th, 2004, 03:38 PM
#21
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|