有效的示例代码,由 gcc 编译但不由 VS 编译器编译:
#include <cmath>
int main()
{
float x = 1233.23;
x = round (x * 10) / 10;
return 0;
}
但出于某种原因,当我在 Visual Studio 中编译时出现错误:
C3861: 'round': identifier not found
我什至包括了 cmath
正如这里有人建议的那样:http://www.daniweb.com/software-development/cpp/threads/270269/boss_loken.cpp147-error-c3861-round-identifier-not-found
只有gcc有这个功能吗?
最佳答案
首先,cmath
不保证带round
进入全局命名空间,因此您的代码可能会失败,即使使用最新的、符合标准的 C 或 C++ 实现也是如此。可以肯定的是,使用 std::round
(或 #include <math.h>
。)
请注意,您的 C++ 编译器必须支持 C++11
对于 std::round
(<cmath>
)。 C 编译器应该支持 C99
对于 round
(来自 <math.h>
。)如果您的 MSVC 版本在我建议的修复后无法正常工作,可能只是因为该特定版本是 C++11 之前的版本,或者根本不符合标准。
关于c++ - 为什么 mingw 知道 round() 但 visual studio 编译器不知道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22306032/