fstream 阻止 math.h 工作

发布于 2024-12-17 23:59:43 字数 1031 浏览 6 评论 0原文

可能的重复:
在 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;

等等)

Possible Duplicate:
cmath compilation error when compiling old C++ code in VS2010
Compilation fails in VS2010 for C++ programs building fine in Linux

I am creating a program in C++ in which I need to read a text file in. I have included the fstream header file, which allows me to open the file, but having added the include, I now receive countless errors relating to math.h functions. Examples:

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 : ';'

Is there any way I can include the text file reading functions of fstream without compromising the math.h functions? And why does this conflict occur anyway?

/Edit/

It seems the errors are in the cmath standard header file. It is nothing I have access to, but for the sake of completion, here is the code that is causing the errors:

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

(etcetera)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-12-24 23:59:43

编译运行:

#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。

您的代码某处有错误。

Compiling and running:

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

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

There is already overloaded definitions for acos(double), acos(float), acos(long double) at math.h, there is no need to use acosf.

There is an error somewhere at your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文