c++visual-studiomacrospreprocessor

How to define preprocessed global macros in Visual Studio 2022


I want to have a global macro in my program (PI 3.14). I read that you have to go to preprocessor->preprocessor definitions->edit and from there you can add your macros. But how do you actually set what the macro is?

I've added the macro PI in the top left. It shows up in my program as equaling 1. How do I make it equal 3.14?

enter image description here

Please forgive me if this is a bad question, I'm a bit new to visual studio and the preprocessor in general.


Solution

  • Please refer to the link:/D (Preprocessor Definitions)

    /D name is equivalent to /D name=1.

    use the way 273K said or in properties->C++->command line:

    /D PI=3.14