【问题标题】:lround on Visual Studio not being recognizedVisual Studio 上的 lround 无法识别
【发布时间】:2014-02-05 03:33:34
【问题描述】:

我正在编译一个在 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 );
}

我可以在 Linux 上使用 g++ 做到这一点。 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 的一些编译器指令?

【问题讨论】:

    标签: c++ visual-studio-2012


    【解决方案1】:

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

    您可以改用来自#include &lt;cmath&gt; 的重载std::round。较新的 Visual C++ 也应该有std::lround

    【讨论】:

    • std::roundstd::lround 均无法识别。我认为 VS 2012 是相当新的。无论如何,就目前而言,我已经通过编写自己的函数来解决这个问题,调用它lround。我仍然想知道为什么这不适用于标准数学库。
    • @unxnut:你有#include &lt;cmath&gt; 我的回答吗?
    • @unxnut:哦,看来std::round 也是 C++11 中的新功能。
    猜你喜欢
    • 1970-01-01
    • 2014-08-30
    • 2021-02-18
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 2020-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多