Sales_item.h: no such file or directory

Hello all,

I recently began teaching myself c++ with a book, c++ primer, and I just started with classes. But when I try compiling my file I get this error message:

1
2
3
4
hello.cpp:2:10: fatal error: Sales_item.h: No such file or directory
    2 | #include "Sales_item.h"
      |          ^~~~~~~~~~~~~~
compilation terminated.


The code in my file:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include "Sales_item.h"


int main()
{
	Sales_item book;

	std::cin >> book;

	std::cout << book << std::endl;

	return 0;
}


From what I've read, it has something to do with a .mk file? I couldn't find anything that precise.

I use nvim on linux.

Any ideas on what could be causing this?
Do you have a file called "Sales_item.h" within the same directory as your hello.cpp?

Sales_item.h is some header file you are expected to create and define a "Sales_item" class within.

PS: You don't need to use header files to practice classes, you could just write
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>

class Sales_item {
  public:
    int price; // or whatever    
};

std::istream& operator>>(std::istream& is, Sales_item& sales_item)
{
    return is >> sales_item.price;
}
std::ostream& operator<<(std::ostream& os, const Sales_item& sales_item)
{
    return os << sales_item.price;
}

int main()
{
	Sales_item book;

	std::cin >> book;

	std::cout << book << std::endl;

	return 0;
}


Last edited on
I found a link to a file with the header name on a subsequent page, they *conveniently* placed it at the end of the section. Thanks.
Topic archived. No new replies allowed.