-4

i was working in code blocks(c++), i am not able to call a function from demo.cpp file in main.cpp under the same project. below is my attached image link for both demo.cpp and main.cpp. i have tried by including demo.h (#include ) but still its showing an error stating that "no such file for directory". someone please suggest some solution.** enter image description here

enter image description here**

  • 1
    This might be a silly question but have you actually written a file called "demo.h"? – john Apr 21 '20 at 18:59
  • 1
    Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the `{}` button to mark blocks of code, or indent with four spaces for the same effect. The contents of a **screenshot can’t be searched, run as code, or copied and edited to create a solution.** – tadman Apr 21 '20 at 19:07

3 Answers3

0

Write #include "demo.h" instead. For further information look here

StackExchange123
  • 1,871
  • 9
  • 24
0

Maybe you should

#include "demo.h"

Because if you use <> you are just telling the computer to search for a library, instead with "" you are telling the computer to search in the current directory. Setting C++ include path via program code line This could be helpful if you want to include a file not in the same directory Hope this will be it and that you find the right answer.

0

As @john notes, there does not seem to be a demo.h file. If a demo.h exists somewhere, maybe it is not specified to your compiler where to look for other header files. If demo.h exists in the same working directory as these two files then maybe you should put them in double inverted commas:

#include "demo.h"

Follow this answer that explains the difference between #include and #include"filename"
The aim is to split the function's declaration and definition into .h and .cpp files respectively. So demo.h needs to contain a declaration like this at the very least:

#pragma once

void min_max(int a[], int i, int j, int& maxx, int& minn);

And then demo.cpp contains the code you specified. Also, the function return type is void so you do not need a return statement at the end of your function in demo.cpp