我正在代码块(c ++)中工作,我无法在同一项目下从main.cpp中的demo.cpp文件调用函数。以下是我对demo.cpp和main.cpp的图像链接。 我尝试通过包含demo.h(#include)进行尝试,但仍显示错误,指出“目录中没有此类文件”。 有人请提出一些解决方案。** enter image description here
答案 0 :(得分:0)
改为编写#include "demo.h"
。有关更多信息,请查看here
答案 1 :(得分:0)
也许您应该
#include "demo.h"
因为使用<>只是在告诉计算机搜索库,而不是用“”告诉计算机在当前目录中搜索。 Setting C++ include path via program code line 如果要包含不在同一目录中的文件,这可能会有所帮助 希望这样,您会找到正确的答案。
答案 2 :(得分:0)
如@john所述,似乎没有demo.h
文件。如果某个地方存在demo.h
,则可能未指定编译器在哪里寻找其他头文件。如果demo.h
与这两个文件存在于相同的工作目录中,那么也许您应该将它们放在双反逗号中:
#include "demo.h"
按照this answer的说明difference between #include and #include"filename"
目的是将函数的声明和定义分别拆分为.h
和.cpp
文件。因此demo.h
至少需要包含这样的声明:
#pragma once
void min_max(int a[], int i, int j, int& maxx, int& minn);
然后demo.cpp
包含您指定的代码。
另外,函数的返回类型为void
,因此在demo.cpp