My main program does see the header files

When I have a header file and an implementation file, if I write the main() function and I write the #include <header file.h> and #include <implementation file.h> I get a message that says: No such file or directory and the program terminates.
But if i put in all the three files in one big file, the program runs Okay.

Please help.
Hi,

When including your own header files put the file name in quotes, rather than angle brackets:

#include "Myheaderfile.hpp" A convention for cpp header files
or
#include "Myheaderfile.h" A convention for C header files

You should not be including implementation files *.cpp or *.c
yes they are in quotes and not in angle brackets. These are example programs in
Water Savitch C++ textbook.

..... and I write the #include <header file.h> and #include <implementation file.h> .....
yes they are in quotes and not in angle brackets.


Maybe you should post the whole of the code you have (don't forget the code tags - the <> button on the format menu), and any compiler messages verbatim.

These are example programs in Water Savitch C++ textbook.


We don't have that book, so it is difficult to provide help in that context.
Here is the code:

//DISPLAY 15.7 Using Derived Classes
#include <iostream>
#include "hourlyemployee.h"
#include "salariedemployee.h"
using std::cout;
using std::endl;
using namespace employeessavitch;
//using namespace std;
int main( )
{
HourlyEmployee joe;
joe.set_name("Mighty Joe");
joe.set_ssn("123-45-6789");
joe.set_rate(20.50);
joe.set_hours(40);
cout << "Check for " << joe.get_name( )
<< " for " << joe.get_hours( ) << " hours.\n";
joe.print_check( );
cout << endl;

SalariedEmployee boss("Mr. Big Shot", "987-65-4321", 10500.50);
cout << "Check for " << boss.get_name( ) << endl;
boss.print_check( );

return 0;
}

Here is the header file:
//DISPLAY 15.1 Interface for the Base Class Employee
//This is the header file employee.h.
//This is the interface for the class Employee.
//This is primarily intended to be used as a base class to derive
//classes for different kinds of employees.
#ifndef EMPLOYEE_H
#define EMPLOYEE_H

#include <string>
using namespace std;

namespace employeessavitch
{

class Employee
{
public:
Employee( );
Employee(string the_name, string the_ssn);
string get_name( ) const;
string get_ssn( ) const;
double get_net_pay( ) const;
void set_name(string new_name);
void set_ssn(string new_ssn);
void set_net_pay(double new_net_pay);
void print_check( ) const;
private:
string name;
string ssn;
double net_pay;
};

}//employeessavitch

#endif //EMPLOYEE_H

Here is the error message:

3 28 E:\Savichexamples\SourceCode\Chapter15\15-07.cpp [Error] hourlyemployee.h: No such file or directory
compilation terminated.

From 15-01 to 15-06 are the headers files and the inplementation files.
I did not post all of them. I only posted 15-01 and 15-07 which is the main program.
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) From the include guards in your header file, it looks as though you've named it "employee.h".

Do you have two header files called "hourlyemployee.h" and "salariedemployee.h"?

Are they in the same directory as the source code? Are they in a directory that's part of your PATH?
Please edit your post and add code tags. Highlight the contents of the file in your post and click the button that looks like "<>". That will make it easier to comment on your code.

That being said, from the comments it looks like your header file is named "employee.h", but in 15-07.cpp you are trying to include "hourlyemployee,h"
//DISPLAY 15.3 Interface for the Derived Class HourlyEmployee
//This is the header file hourlyemployee.h.
//This is the interface for the class HourlyEmployee.
#ifndef HOURLYEMPLOYEE_H
#define HOURLYEMPLOYEE_H

#include <string>
#include "employee.h"

using namespace std;

namespace employeessavitch
{

class HourlyEmployee : public Employee
{
public:
HourlyEmployee( );
HourlyEmployee(string the_name, string the_ssn,
double the_wage_rate, double the_hours);
void set_rate(double new_wage_rate);
double get_rate( ) const;
void set_hours(double hours_worked);
double get_hours( ) const;

Interface for the Derived Class HourlyEmployee (part 2 of 2 )
void print_check( ) ;
private:
double wage_rate;
double hours;
};

}//employeessavitch

#endif //HOURLYMPLOYEE_H

I tried to send all the seven files but I got a message that that said:

Error: contend too long,

But this is the hourly employee that you were talking about
Again, please always use the code tags, have a read of this article on how to do it:

http://www.cplusplus.com/articles/z13hAqkS/


So that your code looks like this:

1
2
3
4
5
6
7
8
9
10
#ifndef HOURLYEMPLOYEE_H
#define HOURLYEMPLOYEE_H

#include <string>
#include "employee.h"

using namespace std;

namespace employeessavitch
{
I have resolved my problem .
Thank you all.......
Topic archived. No new replies allowed.