M_PI flagged as undeclared identifier

前端 未结 5 1720
走了就别回头了
走了就别回头了 2020-12-24 05:36

When I compile the code below, I got these error messages:

(Error  1   error C2065: \'M_PI\' : undeclared identifier 
2   IntelliSense: identifier \"M_PI\"          


        
5条回答
  •  执念已碎
    2020-12-24 06:32

    As noted by shep above you need something like

    #define _USE_MATH_DEFINES
    #include 
    

    However you also include iostream.

    iostream includes a lot of stuff and one of those things eventually includes cmath. This means that by the time you include it in your file all the symbols have already been defined so it is effectively ignored when you include it and the #define _USE_MATH_DEFINES doesn't work

    If you include cmath before iostream it should give you the higher precision constants like M_PI

    #define _USE_MATH_DEFINES
    #include 
    #include 
    

提交回复
热议问题