I've never had a C++ project that has required organizing stuff in folders before, because I mostly use C# for everything, but now I have this kind of project. What I have done is right click on "Header Files" in the solution explorer, and looked for "Add Folder", but there is no such thing. However, there is something called a "Filter", and it appears to work like a folder, but I don't know if this is how C++ uses folders, or what. Is this the case, using filters as folders, or is there a way to make folders?
Thanks for your help.
You can use filters if you like. These place files into pseudo-folders based on their file extensions. By default, you get header files in "Header Files", source files in "Source Files", etc., but these are customizable, as you've found out.
However, if you prefer the Solution Explorer to reflect the file system, then that is an option as well. Just click the "Show All Files" button at the top of the Solution Explorer to toggle it on. The filters will no longer be active (although they'll still be saved with your project settings so that you can toggle them back on at any time), and you will see the folders exactly as they are in the file system. You can drag-and-drop files between folders, create new folders, and everything, just as you normally would.
(overcompressed JPG image stolen from Ben Williams' blog)
I prefer to keep the filters disabled and see the file system in the Solution Explorer. But I'm a control freakāI like files to be exactly where I put them.
The obvious drawback of this, of course, is that you'll see all files in your solution's directory on disk, even those that have not been added to your project/solution. Those that have not been included will appear grayed out or with a dotted outline, and can be easily included by right-clicking and selecting "Include In Project."
You can add projects to Visual Studio solution. Each project would be in separate folder. They also can be stored hierarchically.
Related
I have started learning C++ with Visual Studio 2019 and noticed a strange behaviour. When you create an empty project you are represented with "Filter" files. Now if I active "Show All Files" I can create directories. I created the following structure:
/Core/
/Engine/
Main.cpp
Now if I create a "class" it is, by default, created next to Main.cpp. I would then move the Class.h and Class.cpp into /Core/.
Now if I start editing the newly created files I loose Intellisense. If I uncheck "Show All Files" I get it back. Does anyone else have the same problem?
Another question I wanted to ask was about filter files and project folder structure. Should I use the filter files to organize my project or an actual folder structure? I'm slightly confused because of the Intellisense problem, that's why I'm asking.
And if I should create a folder structure, how should I handle includes like this #include "..\..\... \FileUpInTree.h". In Javascript and Webpack you could define "Alias" Directories to eliminate this. I was wondering if something like this exists for Visual Studio aswell. Maybe namespaces?
Now if I start editing the newly created files I loose Intellisense.
If I uncheck "Show All Files" I get it back. Does anyone else have the
same problem?
I have faced the same issue as you described and when I migrate a file to another folder under the Show All Files filter, Intellisense does not work, which is really strange. When I didn't migrate the file, Intellisense works well at the default address.
And I have reported this issue on our DC Forum and you can add any detailed info on that link and also anyone who is interested in this issue will vote it so that it will make Microsoft attach great importance.
The workaround is that you should uncheck Show All Files and then click it again. After that, Intellisense will turn back and works well.
Another question I wanted to ask was about filter files and project
folder structure. Should I use the filter files to organize my project
or an actual folder structure? I'm slightly confused because of the
Intellisense problem, that's why I'm asking.
Actually, when you use the default project type in c++ projects(not click Show All Files), this structure will automatically identify each file in your project and categorize it into its own filtering folder. At this time, the intellisense works perfectly, because subdividing various files will not conflict.
But in this format, you cannot create folder structure.
Besides, using the filter files or the actual folder structure are the same effect. If you use actual project structure in the Windows Explorer, it will be showed under solution explorer(click Show All Files) automatically.
Suggestion
As long as you do not want to migrate files at will, you can use Intellisense under this filter.
Or
1) create folder structure under Show All Files and then uncheck Show All Files to get Intellisense.
And if I should create a folder structure, how should I handle
includes like this #include "....... \FileUpInTree.h". In Javascript
and Webpack you could define "Alias" Directories to eliminate this. I
was wondering if something like this exists for Visual Studio aswell.
Maybe namespaces?
I think you do not need to worry about this too much.
When you want to use the file under the folder structure of the project, you can just use #include"xxx.h" and the Intellisense will automatically grab the header file in the project.
And if you want to reference a c++ class, you can just use namespace <the c++ class namespace>.
I don't know how this happened, but I have a project where header and source files are not nicely grouped in "Source Files" and "Header Files" directory in the project hierarchy.
Instead, they all sit directly under the project node.
I tried to manually add these folders, but their icons look different than the usual icons, so I guess that isn't the way to do it.
How could I restore these folders?
They aren't folders per se.
What you're looking for are filters, which help organize code without the need of folders.
They're commonly used for separating header files from implementation files.
I am very slowly figuring out Code::Blocks and am trying to set it to my liking.
The gentleman that provided the second answer in this post: Organization of files in Code Blocks seems to be able to get C::B to display his header and source files in a single directory in the project tree. This is what his project tree looks like (and how I want mine to look):
However, in my case, anytime I create a header file, C::B displays it in a new directory called 'Headers' (see image below). I should mention that I am keeping the .cpp and .h files together in the same directory when I am creating the files.
I looked all over environment settings, project properties, C::B documentation, online, tried to ask the poster of the link (but i don't have enough reputation to put comments) and I am stuck. Very stuck.
If you know where the setting in C::B which needs to be changed to display the two file types together (like in the link above), I would really appreciate your help.
The Sources and Headers folders that by default appear to contain
respectively the source and header files of a C::B project are virtual
folders that represent the "categories" (header, source) of the files
within.
To disable this virtual organisation of your project:-
Right-click on your project icon in the project workspace
From the pop-menu select Project tree
In the Project tree sub-menu uncheck the item Categorize by file types
The story
I'm trying to load a C++ project with Visual Studio, and as I used CMake, I used it to generate a .sln file.
My sources files are regrouped in separate folders, but the solution explorer listed them all in a "Source files" folder. Thanks to this question, I solved this first problem.
But then I realized that only .cpp files were listed, so I added new virtual directories one by one to make the folder architecture as it was on my folder list in include side.
But then again I tried to create a new file in a virtual folder, and realized that it didn't move at all at the right place in real.
The question
So now, I just want to forget this "virtual directories" system, and make the solution explorer to be nothing more than a folder tree as it is in real, just like a windows explorer.
Is there any way to do that after an initialization of .sln file with CMake?
UPDATE:
I'm not wishing to use a CMake command because It does not resolve creation problems, nor anything that would pass through the actual solution explorer because each time that I edit a CMakeFiles.txt file, the solution reload reset the solution explorer and I loose every manual include previously done.
I am currently creating a small project over the summer using c++ and visual studio 2010. I wanted to organize the individual .cpp and .h files into their own folders in the project directory. While I use filters in the actual project, I do understand that these are filters, not folders.
So my question is this. In my source, I currently have a header folder called GameStateManger.h, and a folder called Tank_Headers and Tank_CPPs. I also have Tank.h, and Tank.cpp, in their respective folders. My problem is that in GameStateManager, I have this #include "Tank_Headers\Tank.h", however, in my Tank.h, when I type #include... nothing shows up. I cannot find anything. However, if I make a new header, and put it in just source, I can search for those folders. I want to be able to organize my .h files and my .cpp files into individual folders in my source folder, so it is much more organized, considering the project might get very big very soon.
Thank you!
try to use #include "Tank.h"
That should work as long as you add the file to your project first. Drag it from explorer into whatever filter you want it organized it into.
Sorry I forgot to add:
You need to add the subfolder to your project. Go to the project properties, look under C/C++ and add it to Additional Include Folders.