-4

I'm a newbie in C++ programing, I wan to practice each exercise on each seperate cpp files in the same project. How can I do this because VS will result error but I still want to manage all exercises in a project and don't want to make multi-projects for each of them.

5
  • 1
    You can't. Have a separate project for each main()entry level program. These can all exist in a single solution file though. Commented Sep 17, 2017 at 16:20
  • 1
    You can right-click on a source file in the Solution Explorer and select "Properties". Under the props dialog that appears, the first option is "Excluded from Build". You can toggle the Exclude property on/off if you are doing what you describe. Commented Sep 17, 2017 at 16:24
  • It will look something like this when you add multiple projects PHOTO Commented Sep 17, 2017 at 16:25
  • Possible duplicate of Multiple main CPP files in VisualStudio? Commented Sep 17, 2017 at 16:28
  • thanks, the second paragraph really help me. Commented Sep 18, 2017 at 6:15

2 Answers 2

0

You can delete the files that you don't want to use in the Cmake file. For example you have files: ex1.h, ex1.cpp ex2.h, ex2.cpp, ex3.cpp In your Cmake file you have set(SOURCE_FILES main.cpp ex1.h ex1.cpp ex2.h ex2.cpp ex3.cpp) If you want to execute only ex1 delete ex2 and ex3 files.

Sign up to request clarification or add additional context in comments.

Comments

0

This is a recurring issue when you are a student and would like that each exercise works as a standalone application without the overhead of having 100+ projects within the same solution.

The trick is to exclude the file(s) by excluding it from build in its properties, as illustrated in the screenshot below.

Excluding a file from build

Used this method for several years without any issue at the university. :)

1 Comment

Excellent! Don't hesitate to mark the answer as the solution using the little tick. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.