This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
7年前关闭。
我正在用OpenGL在c++中做一个项目,不断地被cmath.h的数百个语法错误所困扰。主要的问题是我根本没有提到或包括cmath。我在一两件事情中使用了math.h,但在我最近进行更改之前,该代码运行得很好。回到以前的工作代码现在显示了相同的错误,所以我有点困惑于从哪里开始寻找。
我是否遗漏了一些很明显的东西,或者这可能是Visual Studio 10的问题?

最佳答案

可能是因为没有(标准)cmath.h
C数学头是math.h,C++也公开这个库,但只是cmath,但是它的所有元素都被提升到STD::命名空间。
在C++项目中,应该包括这样的库:

 #include <cmath>

使用以下元素:
 c=std::sqrt(
       std::pow(a,2)
      +std::pow(b,2));

或者你所发生的任何事情。
参考文献
http://en.cppreference.com/w/cpp/numeric/math

关于c++ - 为什么我从cmath.h中收到数百个语法错误? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13108761/

10-11 10:49