-1

可能重复:
在 VS2010 中编译旧 C++ 代码时出现 cmath 编译错误 在 VS2010 中
编译失败,因为 C++ 程序在 Linux 中构建良好

我正在用 C++ 创建一个程序,我需要在其中读取一个文本文件。我已经包含了 fstream 头文件,它允许我打开文件,但是添加了包含后,我现在收到无数与 math.h 相关的错误功能。例子:

1>c:\program files\microsoft visual studio 10.0\vc\include\cmath(19): error C2061: syntax error : identifier 'acosf'
1>c:\program files\microsoft visual studio 10.0\vc\include\cmath(19): error C2059: syntax error : ';'

有什么方法可以在不影响 math.h 函数的情况下包含 fstream 的文本文件读取函数?为什么会发生这种冲突呢?

/编辑/

似乎错误在 cmath 标准头文件中。这不是我可以访问的,但为了完成,这里是导致错误的代码:

using _CSTD acosf; using _CSTD asinf;
using _CSTD atanf; using _CSTD atan2f; using _CSTD ceilf;

(等等)

4

1 回答 1

0

编译和运行:

#include <fstream>
#include <math.h>

int main()
{
    std::ofstream f("test.txt", std::ios::out);
    f << std::acos((float)0);
    return 0;
}

在 math.h 中已经有 acos(double)、acos(float)、acos(long double) 的重载定义,不需要使用 acosf。

您的代码某处有错误。

于 2011-11-22T17:45:53.260 回答