0

Let's say I have a project directory where it has an include folder that has headers files (.hpp) and a src folder (.cpp). I am using visual studio code. How can I instead of writing #include "../include/Person.hpp" write #include "Person.hpp"? My project has a structure like this:

project-name
     |
     |--src -- Main.cpp & Person.cpp
     |
     |--include -- Person.hpp

My Person.cpp has the implementations of Person.hpp. My main file looks like this:

#include <iostream>
#include "../include/Person.hpp"
int main() {
    Person p("Allison");
    std::cout << p.name << std::endl;
    return 0;
}

8
  • 1
    Possible duplicate: stackoverflow.com/questions/37522462/… stackoverflow.com/questions/57458423/… stackoverflow.com/questions/52910102/… Commented Nov 17, 2020 at 0:56
  • 2
    It looks like you need to add the include paths twice: once in c_cpp_properties.json for intellisense and once in tasks.json for the compiler to build it. Commented Nov 17, 2020 at 1:02
  • g++ -l ./include ./src/main.cpp -o ./bin/main.o gives fatal error: "Person.hpp": No such file or directory Commented Nov 17, 2020 at 1:10
  • Should it have been ../Include instead of ./Include in the above comment? Also remember this path has to be relative to the main.cpp file I believe. Commented Nov 17, 2020 at 1:35
  • Tried that too... the same error Commented Nov 17, 2020 at 1:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.