Sep 7, 2010

Put your C++ code into directory in Visual Studio

Wow, finally, I found the way to put C++ codes into different folder, as well creating and managing those folders in Visual Studio.

Before, all I have been doing is creating .cpp and .h files in the same root folder (where all your codes goes) and assign them to created filters. This, however, become an disadvantage when I switch from writing small program on my own to teamwork for my projects.

A filter in Visual C++ is, basically, a filter. It is not a directory that you put your code files into but rather some kind of "tag" that help you identify your code file. This makes your project cumbersome when you want to put the files into folders, each with a purpose (like Project\Logic, Project\GUI, etc)


Okay, that's enough of the chit chat, now let's do it



Show All Files
First, from the Solution Explorer (left side of the window by default / View-Solution Explorer / Ctrl + Alt + L ), click the "Show all files" button.
Solution explorer with directory
After that, you should see something like this panel. All the folders in your project will be displayed here. By default, there will be one folder called Debug (for temporary compiled files during debugging process) and another folder with the name of your project (SRS_HK for my case).
All you files should also be listed according to the directory they belong.
You can press the "+" / "-" button to expand, collapse your directories.

Finally, you can add in folder and files by right-click, Add -> New Folder / New Item




Of course, putting your files to folders requires some modification to the #include command. For example, you have to use
#include "SRS_HK\SimpleException_HK.h" 
to include the header file now.

Hope it helps :)