A note on Visual Studio
This error:
The "CL.exe" command terminated by code 2. |
Means the compiler crashed.
I get this on VS2019 (not so much on VS2017) in certain situations.
I don't see this in your code, but when I write (accidentally)
...forgetting the return, VS2019 crashes instead of informing of the missing return.
By default, if you start a "console" project where the compiler fills in the project with a basic main function, it usually enables pre-compiled headers (the PCH file mentioned in post(s) above).
If you start an empty project, it usually doesn't.
If you don't use or have pre-compiled headers in your project, or you want to remove them, you must manually disable this setting if it was automatically put in the project definition. There will be one "CPP" file with "create pch" and the others will "use PCH", but you need "no using" pch.
PCH is ok to use, but if it gets in the way at all, especially for student projects, it's best not to have them.
Although it is an extra step, I can recommend checking your installation so as to include Clang. VS2019 can download and configure Clang 8 in one step. It is never selected on a new project by default. You can, however, choose clang as the toolset. If/when you do, VS2019 copies (or leaves in place) some of the settings for MSVC compiler. You have to "shake it" - close the project, then re-open - it "figures it out", and then Clang works quite well (better than MSVC).