The default directory, where are the new classes stored?

I have a C ++ project in Visual Studio 2010. If I right-click my project in visual studio and select Add-> Class, it will create .h and .cpp files in the same directory where my .sln file is located.

How to set another default folder in which the created files should be stored?

+6
source share
5 answers

No, by default Visual Studio will add a new item to the project root directory.

+1
source

you need to right-click on the folder where you want to add these new files, and then go through the same process of adding a file.

0
source

My advice is to always right-click on a project / solution when you want to Add something to your project, and then use the Location edit box in the file dialog box that VS throws out to put your items in the right place. Visual Studio seems to remember this place for the rest of your coding session, but, annoyingly, quickly forgets it if you close and reload the solution or exit VS.

I use the method above to manually create .cpp and .h files when creating a class. I stopped using the parameter of the Add Class element at that time because, as you discovered, it does not offer to set the location of the place where the resulting files will be returned. To right-click on a project, select Open Folder in File Explorer on the menu to open Windows Explorer for files, and then cut and paste .h and .cpp files into the folders in which I wanted them to quickly become tedious.

I would also like to know if there are better ways to “mix up” Visual Studio with the way we physically construct the folders of our projects more seamlessly and integrated. Perhaps the VS team needs to expand the Solution Explorer to help with the physical structure of folders, rather than being limited to logical filters? I suspect there are non-trivial reasons why this has not yet been done.

0
source

To do this, use Add-> New Item, and then add the cpp file and header separately. A bit more work, but for some reason you can choose a folder when using a new item.

0
source
  • "Add - new item ..." CLASSNAME.h in your project group, then select the desired folder
  • "Add - new item ..." CLASSNAME.cpp in your project group, use the last saved folder
  • "Add class - C ++ class" and first enter CLASSNAME in the class name field.
  • Use the .h / .cpp file to search for created classes.
  • OK A fragment of the new class will be merged with the empty cpp / h file created earlier.
0
source

Source: https://habr.com/ru/post/910694/


All Articles