0

我创建了一个空白的 Win32 C++ 项目。即使我包含了 math.h 或 cmath 库,编译器也会继续为 round 函数提供 C3861 未定义错误。

我试过以下

1. adding the /TC compile as C++ and using cmath
2. adding the include _MATH_DEFINES_DEFINED 
4

2 回答 2

0

您是否要四舍五入到整数?

std::round()不返回 int 值,

而是尝试:

int a = int(std::floor(var + 0.5));

更多解释:http ://en.cppreference.com/w/cpp/numeric/math/round

于 2015-06-11T09:10:10.037 回答
0

Visual Studio 2012 (MSVC 11.0) 没有严格遵循 C++11,所以它可能没有 std::round。

利用

inline double round(double value) { return value < 0 ? -std::floor(0.5 - value) : std::floor(0.5 + value); }
// analogously for float
于 2015-06-11T09:15:41.543 回答