c++ - Visual Studio 中的 M_PI 问题

标签 c++ visual-studio-2012

我在使用 Visual Studio 2012 编译包含 cmath 的 C++ 项目时遇到问题,我收到此错误

error C2065: 'M_PI' : undeclared identifier

我试过这个 M_PI works with math.h but not with cmath in Visual Studio但它根本不起作用

我该如何解决这个问题?

编辑

我几周前下载的应用程序源代码不稳定。所以今天我尝试下载更新的源,现在它就像一个魅力

最佳答案

把下面的代码放在一个头文件中,并包含在你需要M_PI的地方

#pragma once
#include <cmath>
#ifndef M_PI
namespace
{
    const double M_PI = std::acos(-1.0);
}
#endif

关于c++ - Visual Studio 中的 M_PI 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22502952/

相关文章:

c++ - 如何在 C++ 初始化时重载分配运算符以分配对象

python - 在输入时保持 Visual Studio (Python) 中的当前缩进?

.net - 混合模式程序集是针对运行时的 '2.0.50727' 版本构建的,无法在 4.0 运行时中加载

visual-studio-2012 - 在 Visual Studio 中查找对重写方法的所有引用

c++ - 处理来自Unrar DLL的错误

C++ bmp 按位运算符

c++ - Cxx.jl Julia Complex 和 std::complex 之间的转换

c++ - 如何显示猜测数字的尝试

tfs - 重命名文件夹后无法解决挂起的更改

visual-studio-2012 - 在 VS 2012 中导入 SvsServiceProvider