Include Problems

I am having a problem with my file includes, I get this error, and I don't see why because it is in the project:

Error 1 error C1083: Cannot open include file: 'shop.h': No such file or directory c:\users\dylan\documents\visual studio 2013\projects\robot masters - text based\code\functions.cpp 2 1 Robot Masters - Text Based


main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
 #include "functions.h"
#include "shop.h"

int main()
{
	welcome();
	caller();

	std::cout << "" << std::endl; // for testing
	system("pause"); // for testing

	return 0;
}


functions.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 #include "functions.h"

void welcome()
{
	int balance = 100;
	std::cout << "Welcome to Robot Masters" << std::endl;
	std::cout << "Balance: $" << balance << std::endl << std::endl;
	return;
}

void help() // List of functions
{
	std::ifstream file("help.txt");
	std::string line;

	getline(file, line);

	while (file.good())
	{
		std::cout << line << std::endl;

		// Gets next line
		getline(file, line);
	}
}

void caller() // Checks what function to call
{
	std::string call;
	bool check = true;

	std::cout << "What function do you want to call?" << std::endl;
	std::cout << "Hint: type 'help' for a list of avalible functions" << std::endl;

	std::cin >> call;
	std::cout << "" << std::endl;

	while (check == true)
	{
		if (call == "help")
		{
			help();
			check = false;
		}
		else if (call == "shop")
		{
			displayShop();
			check = false;
		}
		else
		{
			std::cout << "That is not a function" << std::endl;
			std::cout << "Hint: type 'help' for a list of avalible functions" << std::endl;

			std::cin >> call;
			std::cout << "" << std::endl;

			check = true;
		}
	}
}


functions.h
1
2
3
4
5
6
7
8
#include <iostream>
#include <string>
#include <list>
#include <fstream>

void welcome();
void help();
void caller();


shop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "shop.h"

void displayShop() // Displays shop
{
	std::ifstream file("shop.txt");
	std::string line;

	std::cout << "Welcome to the robot shop!" << std::endl;
	std::cout << "Avalible Items: " << std::endl << std::endl;

	while (file.good())
	{
		// Gets item
		getline(file, line, ' ');
		std::cout << line << " = $";
		// Gets price
		getline(file, line, ' ');
		std::cout << line;
	}
}


shop.h
1
2
3
4
5
6
#include <iostream>
#include <string>
#include <list>
#include <fstream>

void displayShop();
Last edited on
Update: my code files were in the wrong place, i put them in the right place now but im still getting errors:

Error 2 error C3861: 'displayShop': identifier not found c:\users\dylan\documents\visual studio 2013\projects\robot masters - text based\code\functions.cpp 47 1 Robot Masters - Text Based

Also, are my #include ... correct?
Last edited on
In 'functions.cpp' you haven't actually included 'shop.h' which contains the prototype for the function you are trying to call. You may have included it in 'main.cpp' but that only includes it in the scope of that source file, therefore you need to include it in your functions source file too.
Last edited on
Oh yeah thanks man, its fixed
Topic archived. No new replies allowed.