How to make Visual Studio automatically detect a .cpp file in a subfolder? - c++

As it's described in the title, I would like to make Visual Studio detect a .cpp file which is in a subfolder. (It's a C++ project.)
My program automatically creates new .cpp files and .h files, but when it creates a new .cpp, it doesn't detect the .cpp file in the subfolder of the project. Even if I restart the project/program.
What could I do to make it automatic?
Does an instruction exist to tell Visual Studio/or the program to compile this .cpp file ?
Does every .cpp file have to be in the same folder? I could do it that way, but it would be more organized if the different files are in different folders.

So I didn't find any solutions, but I've ask severals persons, and they told me that I might have to change by hand some files automactly created by Visual studio to tell them to include a specific .cpp file. But to identify which file I've to change and if I can open them as a txt file ect.. It was too much work, then I've decided to change my project.
Thanks for your help ! And I hope this will give you a little taste of what you have to do if you have the same problem

Related

How do I run .cpp files in Visual Studio?

I have been following tutorials which have me download and unzip projects which contain .sln files for me to open. Following them this way is pretty easy. However, I want to be able to download a single .cpp file and run it without creating a project. I just want to get straight to into it. In Code::Blocks, setting this up is easy to figure out. For some reason, I can figure it out in Visual Studio.
I want to be able to download a single .cpp file and run it without creating a project.
You cannot. Visual Studio does not support this. A project is always required, even if it only contains a single source code (.cpp) file.
You can, however, run a single .cpp source file through Microsoft's C++ compiler on the command line (cl.exe), and then execute it. But this doesn't involve anything about the Visual Studio IDE.
if you have the source code, you could make a .cpp file by right-clicking and adding one and then ctrl+s then f5 and it might run... Idk.

Automatically add .cpp files to Visual Studio 2019 project

I wrote a small code generator but I dont know how to automagically include the generated files in the project automatically.
My first try was to write into the .vcxproj file, but this prompted a windows saying that the project file was modified and I want to auto-reload (there is an option to auto-reload changed files, but this only works for existing files in the solution )
My second attempt was to add a wildcard to the .vcxproj file to compile all .cpp files in a given folder. This worked but as soon as I tried to add a new .cpp normally from within VS I got an internal error.
Any ideas?

How do I display the .cpp and .h files in the left side of the the codeblocks ide?

When I create a new project it automatically shows me the .cpp files in under Workspace>Project>Source and .h files in headers. If I then save it and close Codeblocks and open the project again, it will only display the main.cpp and further add .cpp and .h files if I create more classes.
How can I make it display the .cpp and .h files neatly like when I work on a new project?
If I am not getting it wrong. Your codeblocks saves the project with the extension .cbp.
First, Open your project.
Go-to View.
Click Open files list. You will see a list of all files currently being shown on the right-side of the editor.

Is it possible to read/retrieve a c++ source code from a .sln file?

I sent a .sln file (instead of .cpp file) to a friend; will he be able to read the source code from it or is it just a file used from Visual Studio to load projects?
No, SLN files only store the project settings. You should send him the whole project in a compressed file.
Just so you know, the recommended way to share code with other people is using a version control system, like GIT.
No, a sln file only contains references to your files. So at least he now knows the name of your file ;)

Eclipse CDT: How to make separate header folder?

I was trying to separate my header files (.h) from my (.cpp) implementation by storing them in two different source folders. However, Eclipse then tells the compiler to look for the .h file in the same folder as the .cpp file. This causes the compiler to stop as it can't find the specified file. Is there any way to create such folders in Eclipse and get around this issue?
In visual studio there is separate folder for header files so can we make a separate folder for header files in Eclipse CDT too?