-2

So i was trying to make a windows terminal like console with c++ but i ran into a problem.

I use VS 2022 and my file directory is like this:

Project

\-Headers
  \--Header.h
\-Source Code
  \--Main.cpp

I was trying to import "Header.h" into "Main.cpp" but i ran into the "cannot open Header.h file" error.

So how do i do this properly?

An explanation of why my code does not work and how to do it properly.

Example code:

#include "Header.h" //error here

Ducc
  • 1
  • 1
  • Add the `-I` (upper-case i) option when building to add a directory to search for header files. Or use e.g. `#include "../Headers/Header.h"`. – Some programmer dude Aug 28 '23 at 18:02
  • Your compiler will by default only look in the same folder as the cpp file, the Additional Include Directories or system paths when that fails. If your header is in some other folder you have to add that other folder to the include directories it looks or use a relative path. In Visual Studio you can add a folder to the `Properties-> C/C++ -> General -> Additional Include Directories` setting of your project to solve this. – drescherjm Aug 28 '23 at 18:03
  • 1
    Helpful reading: [How do include paths work in Visual Studio?](https://stackoverflow.com/q/2676417/4581301) – user4581301 Aug 28 '23 at 18:03

0 Answers0