Copying source files into a Visual Studio project - c++

I've created a new Visual Studio C++ project and I'd like to import copies of a number of C and header files into the project. That is, the files are currently in a folder on my desktop and I'd like to import them such that copies are placed in the newly created project folder.
How would I do this? I've tried using File | New | Project from Existing Code but that just keeps the files in their existing location. I've even tried a simple Ctrl-C and Ctrl-V and again that imported the files but they stayed in the same place on disk.

Copy the files to the new location in Windows Explorer, then start Visual Studio and add them as existing items to the project.

I think the better solution would be to create a new (empty) project and add your h and cpp files per "Add -> Existing item" in the context menu of "Headers" and "Sources"

Related

How do I automatically include folders and files to the deployment project in visual studio?

I have a c++ project in visual studio and a folder called assets, in the same location as the source file, that contains folders for music, sound effects and images that my c++ game uses. That folder must be placed in the same folder as the .exe file of the game.
I have created a deployment project for the c++ project. However, it seems like I need to manually add these folders (assets, images, music, etc.) and files to the File System on Target Machine.
Is there a way for visual studio to add these folders and files automatically?
I have not managed to find anyting online for how to do that so far.
Thanks.
This link provides many methods. You could drag all the files you want to add into the file system view. Or you could right click on the folder in explorer and click copy and then right click the folder in the file system view in the setup project and click paste.

Visual Studio 2010, error when including headers from another folder within the same solution space

I am new to Visual Studio 10 c++, I imported a sample project, the project came with multiple folders in the same solution space project, each with files in it, including any of those files in any other file within any of the project worked perfectly then I added another filter to the project, it worked fine but the files in it can not be included in any of the original project files, is there anything am missing out? I followed these instructions when creating the folder
Right Click project
Click Add
Select New Filter
change Filter Name
Right Click Filter
Add
Select Class
And could someone tell me how to make the Filters and file in them visible in explore, the Sample project came with Visible Filters/Folders so there has to be a way of making them visible in explore and VS, here are Images showing what I mean, in the project I have the laneDetector filter which does not exist in project folder
Showing My VS project layout with LaneDetector filter/folder visible
Showing My VS project in explore with no LaneDetector filter/folder

How to create a folder in Visual Studio C++ 2012

I have started my first bigger project with Visual Studio 2012 in C++. I will structure my Source-files in folders, but I can not find where I can create real folders, like in the windows explorer. So here is my question.
How can I create real folders in my project?
The IDE has a command for that, "New Folder". It is even present in the Project + Add context menu, something you can see when you look at the context menu with Tools + Customize. It is however hidden in the C++ IDE. Intentionally.
Its important to understand why it is hidden. It keeps you out of trouble, the kind of trouble you'll get into when you create folders with Explorer.
At issue is the way C++ files get built. They produce an .obj file when the compiler is done with them. That obj file is stored in a directory whose name is a project setting. You see it with Project + Properties, General, Intermediate Directory setting. For an individual .cpp file, it is C/C++, Output Files, Object File Name. The default for that one is $(IntDir) a macro that tells the compiler to use the Intermediate Directory setting. With the default settings, all .obj files for the Debug build end up in the Debug subdirectory. Release subdirectory for the Release build. Regardless where the .cpp was stored.
Maybe you see the bear trap by now. If you create a subdirectory with .cpp files then you'll get in trouble when that subdirectory has a .cpp file whose name is identical to another .cpp file in another subdirectory. They produce an .obj file with the same name. One overwrites the other, which ever one was compiled last. That produces very mystifying linker errors. You'll get duplicate symbol errors because the last built .obj file is linked twice and missing symbol errors for the overwritten .obj file.
So go ahead and create a subdirectory but beware this problem. You have to change the Object File Name setting for the .cpp file if such a collision happens.
This is mildly annoying, however, here is what can be done:
Create the new folder in Visual Studio. This does not create a new folder in the file system. Add a new item to the folder. Choose the proper directory for the item.
For example, if your project is at %Documents%\Project, and your new folder name is Folder, then you add a new item to that folder at %Documents%\Project\Folder.
Visual Studio 2012 will put the item in the folder where you want it. If you add a new item, it will default to the same folder. That is where the annoying part comes in. If you create 3 folders for all your project items and try to add a new item to each folder, Visual Studio will try to put all 3 items in the same place in the file system (the last folder you added a new item to), while putting items into the correct Visual Studio folder.
It is possible there is a setting for this in Visual Studio. I haven't found it. I also haven't looked that hard.

Add folders in a visual c++ project

How can I add whole folder and its subdirectories in a visual c++ project? I am using visual studio 2010 professional. I mean you can add files by using Add Existing Item but how do you add a whole directory?
The quickest way that I know of is to
add the folder to your project file directory using Windows Explorer
find the folder in Solution Explorer (make sure Show All Files is checked)
right click on the folder and select Include In Project
You may have to do the folder and the files separately, but you can select multiple files at once.

Visual Studio 2010 new C++ project from existing code

I want to modify an existing project but put all the source and header files etc. into a new directory to keep them separate. When I use the "create new project from existing code" option, the solution files seem to point back to my original .cpp file which I don't want.
Q - what the best way to do this?
The Visual Studio projects are simple XML files that can be edited. Just bulk replacing the paths in your favorite text editor is probably the easiest way to go (I do that all the time).
create a new project, without opening the existing one.
then copy all the header and the cpp files from the older folder to the new project folder.
'add existing item' will only point to the original file only.