Visual Studio上的lround无法识别

时间:2014-02-05 03:33:35

标签: c++ visual-studio-2012

我正在编译在Windows 7上的Visual Studio 2012中使用lround的库。代码非常简单:

#include <iostream>
#include <math.h>

int main()
{
    double dfoo = 42.546;
    int ifoo = lround ( dfoo );

    std::cout << dfoo << " => " << ifoo << std::endl;

    return ( 0 );
}

我可以使用g ++在Linux上执行此操作。 MSDN论坛说它应该编译。然而,Visual Studio给出了错误,指出找不到lround。确切的错误是:

1>------ Build started: Project: testnorm, Configuration: Debug Win32 ------
1>  testnorm.cpp
1>c:\users\sanjiv\documents\visual studio 2012\projects\testnorm\testnorm\testnorm.cpp(7): error C3861: 'lround': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

有人可以看到可能出错的地方吗?我错过了Visual Studio的一些编译器指令吗?

1 个答案:

答案 0 :(得分:0)

您正在尝试使用C99数学函数,但Visual Studio不是C99编译器。

您可以改为使用std::round中的重载#include <cmath>。较新的Visual C ++也应该有std::lround