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?
3 Answers
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.
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.
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.

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.