why visual studio 2022 can't compile it

alaamer 1 Reputation point
2022-12-30T22:57:05.873+00:00

I found a code in a book for the C++ language. The important thing is that I ran this code on Visual studio 2022. It didn't work.
I tried it on codeblocks. it didnt work
I tried it on any online (compilers) on Google, it worked
so whats the problem?
Note: I am not the one who wrote it, I just copied it from the book

Developer technologies | Visual Studio | Debugging
Developer technologies | C++
{count} votes

1 answer

Sort by: Most helpful
  1. Tyler Whitney 0 Reputation points Microsoft Employee
    2023-01-11T21:22:05.43+00:00

    Another issue may be that the Microsoft C++ compiler uses switches to determine which version of the language standard to compile. For example, if the code you are trying to compile uses C++ 20 language features, you need to pass /std:c++20 to the compiler if you are using the command line compiler. If you are using Visual Studio, then you right click your project in solution explorer > properties > C/C++ > Language and set the C++ Language Standard dropdown to ISO C++20 Standard (/std:c++20).

    As others have said, w/o knowing what you are trying to compile, there is little additional help we can offer.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.