C++/Header file
Expert: vijayan - 5/18/2009
QuestionHi
I have a question about the below,can you tell me whats the problem with it that every time i compile it,it shows me this error:"fatal error C1083: Cannot open include file: 'GradeBook.h': No such file or directory"
what should i do for taking away this error?
#include <iostream>
using std::cout;
using std::endl;
#include "GradeBook.h" // include definition of class GradeBook
// function main begins program execution
int main()
{
// create two GradeBook objects
GradeBook gradeBook1( "CS101 Introduction to C++ Programming" );
GradeBook gradeBook2( "CS102 Data Structures in C++" );
// display initial value of courseName for each GradeBook
cout << "gradeBook1 created for course: " << gradeBook1.getCourseName()
<< "\ngradeBook2 created for course: " << gradeBook2.getCourseName()
<< endl;
return 0; // indicate successful termination
} // end main
Thanx
Bita
AnswerThe error is self-explanatory - the preprocessor can not find the file "GradeBook.h"
Generally, it is necessary to tell the preprocessor where to look for header file if it is not placed in the same directory as the file containing the #include directive or a standard system directory.
You could:
a. place the file "GradeBook.h" in the same directory as the file with main()
b. use a relative path specifier eg. #include "../my_include_files/GradeBook.h"
c. use a complete path specifier eg. #include "/usr/home/me/src/my_include_files/GradeBook.h"
d. tell the preprocessor which additional directories are to be searched to locate header files. How to do this is implementation-specific; you need to look at the documentation for the compiler that you are using. In case of the microsoft compiler that you seem to be using, see:
http://msdn.microsoft.com/en-us/library/73f9s62w(VS.80).aspx
also note: on posix systems, file names are case-sensitive. GradeBook.h" is different from "gradebook.h"