question

FyMa2618-9573 avatar image
0 Votes"
FyMa2618-9573 asked FyMa2618-9573 commented

Problem whit Visual Studio / C++

Good day,
i am new in Visual Studio, i make a C++ project.
On my snl. file i had activated all files usw., but when i try to include a headerdata its dont work(Only when its in a other Folder.) Anyone know what i can do?
Thanks in Advance.

c++
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

You'll need to explain your problem in more detail before anyone can do anything other than guess at what your problem is.
By adding more detail it's likely that you'll spot what's wrong yourself too :)

1 Vote 1 ·

Good day, thanks for response,
i am make a Project in Visual Studio in the Language C++ / C.
I had a solution file where i had set the option show all datas on, i´ve made 1Headefile where i put many code in but when i want to include the Header file in a other its dont work.
I think thats because, i have a few Folder (See Picture bellow)and i had the Header file that i want include in a other folder than the script where i want to make #include "..", but i am dont know how to fix the Problem(I tryed to put it in the same Folder as the other script and it worked).100303-explorrer.png`


0 Votes 0 ·
explorrer.png (11.8 KiB)

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered FyMa2618-9573 commented

Firstly bear in mind that the Solution Explorer UI for a C++ project does not necessarily indicate the actual folder structure on disk. C++ only cares about the folder structure on disk, not Solution Explorer. In a default C++ project it groups .cpp files under Source Files and .h/.hpp files under Header Files but that has nothing to do with the underlying disk structure.

When you use a #include you must use the disk structure. So imagine you have this structure on disk (not Solution Explorer as it doesn't matter).

\MyProject
MyProject.cxproj
\Utility
Utility.h
\Window
Window.h
Window.cpp
MyCode.cpp

To reference the utility.h file in MyCode.cpp you would simply include the relative path from the source file #include ".\Utility\Utility.h"

If you have a heavily nested project structure then note that it gets complicated fast as you have to walk back to the shared root and then down. For example to reference utility.h in Window.cpp you'd need to walk back one directory and then down #include "..\Utility\Utility.h".

For a really complex project this can get unmanageable so an alternative approach is to modify the project's properties and add the common include paths that you might use as part of the #include search paths. You can then go back to the standard #include "Utility.h" syntax and let the compiler find the files.

Finally note that the Show All Files features in Solution Explorer is useful for quickly adding a bunch of files that aren't in the project to the project as far as the compiler is concerned. In general you shouldn't leave it on however as this can be confusing. Also note that really only .cpp files matter for the compiler. Header files can be added to the project to make them easier to see and manage but the compiler doesn't care about them unless a source file somewhere has a #include for them.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It worked, thanks!

0 Votes 0 ·