如何包含其他文件夹中的文件? [英] How to include a file from another folder?
问题描述
在我当前的项目中,我将我的类文件和头文件分开了。我的项目结构目前如下所示:
In my current project I have separated my class files and my header files. My project structure currently looks like this:
-
项目
Project
- 来源
- src
- class1.cpp
- class2.cpp
- 标题
- 包括
- class1.h
- class2.h
我的问题是我不知道如何将头文件包含到课堂中文件。我无法链接到不在同一级别或子文件夹中的标头?或者是否有一些方法可以从项目根目录中继续下去?例如:
#includeProject / Headers / include / class1.h
在class1.cpp文件中My problem is that I do not know how to include the header files into the class files. Am I unable to link to headers that are not at the same level or in a child folder? Or is there some way to go from the project root and work my way down? For instance:
#include "Project/Headers/include/class1.h"
inside the class1.cpp file推荐答案
假设你想让class1.cpp包含class1.h你会做这样的事情
Assuming you want class1.cpp to include class1.h you would do something like this
#include "../../Header/class1.h"
..
告诉操作系统在编译器要求输入文件时跳转1个目录。The
..
tells the tells the OS to jump 1 directory up when the compiler asks for the file.这篇关于如何包含其他文件夹中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 包括
- src