unable to find my headers when in another file

please help I am trying to make my programme more manageable by splitting the header files into different folders. however when I compile I get this message
[Error] ../battle/battle_generator.hpp: No such file or directory
I searched online and founf that,

#include "../folder/header_file.hpp"

was the correct way to do this, it does not seem to work

I am using the latest version of dev c++


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "startscreen.hpp"
#include "intro.hpp"
#include "../battle/battle_generator.hpp"
#include <time.h>
 
 using namespace std;

  int main()
	
{
srand(unsigned(time(0)));// so that the numbers are random
startscreen();
intro();
while(HP>0){
	battle_generator();}
 


please help!
Where are these files in relation to each other?

Using ../ with relative includes like that is bad practice, where on the internet did you see it was the right way??
thanks for the quick response

I have my main folder where the programme is stored. where the .cpp file is. I then in the same folder have more folders in which to store my header files. as I have quite a lot.

the battle folder in which the battle_generator header is housed is in the same folder as my main cpp.

how can I include the headers from these files in my main.cpp

I searched how to include a header from another folder in c++ and all the sites told me that was the way to do it.
Just remove the "../" part and I think it should work for you.
thanks that seems to work :)
in terms of folders, .. means the parent folder and . means the current folder. there should be a compiler flag that lets you add a directory to the search path, so you could then do #include <battle_generator.hpp> , which, and I think LB would agree with me but lets see, is a better method because then none of the files are staticly placed
Actually, I would strongly disagree. The only path that should be added to the include search directory list is the root directory of your project.
so you mean (what the flag? -I i think, because -L is for adding linking dirs) g++ -I$PROJECT_ROOT

then #include <battle/battle_generator.hpp> ? but then wouldnt the files that include them be more static in how they are layed out in the projec? with my way, you can move them anyway you please, and just have to update the makefiles (or the generators)
Folders are like namespaces. What happens if you have both <battle/generator.hpp> and <map/generator.hpp>? If you give them unique names, what's the point of putting them in different folders?
Last edited on
ah i see what you mean. yeah i like that better.
If you give them unique names, what's the point of putting them in different folders?
to be better organized (see sfml)
Topic archived. No new replies allowed.