How can I make Visual Studio save my C++ files in a specific folder?
Asked by
_posted yesterday
I'm a complete beginner learning C++ in Visual Studio. I created a folder for my files and even tried opening Visual Studio from that folder, but new files created through the File menu are treated as unsaved documents and Visual Studio asks me to choose a location for each one when I close it. I'd like my .cpp files to be saved automatically in the folder I choose. What is the correct way to set this up?
Answers
When creating a new project, check the project location field and select your preferred parent folder. After the project is created, all files added through the project in Solution Explorer will use the projectโs folder structure. You can also change Visual Studioโs default project location in its settings, but that only controls the starting location for new projects; it doesnโt automatically save loose files opened from a folder.
Reply to this answer
The easiest approach is to create a C++ project in the folder you want, then use Solution Explorer rather than the general File > New File command. Right-click the project or its source-files folder, choose Add > New Item, select a C++ file, and give it a name. Visual Studio will add and save the file inside that project automatically.
Reply to this answer
Opening a folder in Visual Studio and creating a new file from the main File menu is different from adding a file to a C++ project. A project keeps track of its source files, while a loose new document has no permanent location until you save it. Create or open the project, find it in Solution Explorer, and use Add > New Item there.
Reply to this answer
Add your answer
Answers are reviewed before publication.
_posted yesterday: I was opening the folder and creating a file from the File menu, so it stayed as an unsaved document. Iโll try adding the file through Solution Explorer instead.