我的 main() 文件中不能包含头文件

时间:2021-01-21 20:54:56

标签: c++ visual-studio

所以我有以下文件结构:

  • 图形(文件夹)
    • RenderCore.h
    • RenderCore.cpp
  • MainProject(文件夹)
    • app.h
    • app.cpp
  • 水(文件夹)
    • WaterRenderer.h
    • WaterRenderer.cpp

我可以使用 #include <Graphics/RenderCore.h> 中的 WaterRenderer.h,或项目中任何其他文件夹中的任何其他头文件。除了app.h

出于某种原因,当我尝试使用 #include <Graphics/RenderCore.h>#include <RenderCore.h> 时,我收到一条错误消息,告知该文件不存在。

同样适用于任何其他文件夹中的任何其他头文件,如果我尝试将其导入 app.h

但是,如果我将 app.happ.cpp 移动到不同的文件夹中,我可以使用上述包含,但我无法启动该程序,因为它要求我“选择一个有效的启动文件”。

有人知道可能的解决方案或至少是原因吗?我在 Windows 10 上使用 VisualStudio 2019。

1 个答案:

答案 0 :(得分:0)

包含头文件的方法有两种。

  1. 直接在源程序头部​​添加完整路径

    #include "D:\testfolder\Graphics\RenderCore.h"

  2. Properties->VC++->Include Directories->add the path

注意:Solution Configuration的设置需要与Properties上的设置一致

enter image description here enter image description here

相关问题