How to run one C++ program when multiple files are in one project:
How to Remove
When you want to compile one program but you have multiple .cpp files in the project, you need to exclude or remove the files you don't want in the project. For example, if you have hello.cpp and lab2.cpp in one project, and you want to compile hello.cpp, you need to remove lab2.cpp. If you value the old file, beware that you do not delete the file when you remove it.
To do this in Visual Studio, right click on lab2.cpp under the solution
explorer, choose
Exclude from Project.
See the following image.

- XCode: Right-click on old .cpp files you don't need and select delete. Read the pop up menu carefully if you want to keep a copy of the file for later.
- Code::Blocks: Right-click on old .cpp files you don't need and select "Remove from project".
- repl.it: Not recommended, but you can try this. Click the vertical dots after the file name and select "Delete". The default file main.cpp cannot be deleted, instead delete you can make a copy of the code in a new file, then delete the code from the default main.cpp file.
How to Add
When you want to add an existing C++ file to a Visual Studio project, here is what to do.

- XCode: Drag and drop new files in to the yellow folder inside your project that has the same name as your project. Check the "Copy items if needed" option to be sure new code files are placed in the project folder. Be sure right-click and delete old .cpp files you don't need.
- Code::Blocks: Put the file in the project folder, then right click on the open project in Code::Blocks and select "Add files..."
- repl.it: Click the vertical dots at the top right of the Files area and select the "Upload file" option.