gpt4 book ai didi

c++ - 错误 : implicit declaration of function `int open(...)'

转载 作者:行者123 更新时间:2023-11-28 05:09:06 24 4
gpt4 key购买 nike

我在 Solaris 操作系统上的一个 C++ 项目中使用 open 函数。

#include <sys/types.h> 
#include <sys/stat.h>
#include <fcntl.h>

char in_pathname[PATH_MAX];
int in_fd = -1;
in_fd = ::open(in_pathname, (O_RDWR|O_CREAT|O_TRUNC), 0600);

使用上面的行我得到以下编译错误。

函数 `int open(...)' 的隐式声明

知道为什么会这样。

注意:这个源码很老了,我用的是gcc 2.95.3版本编译的。

最佳答案

一些(较旧的)编译器会允许您使用未声明的函数并假定它返回 int。

如果您使用一个文件但没有包含声明它的 header ,就会发生这种情况。您似乎正在使用文件的打开方法,并且 these docs因此建议你需要

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

关于c++ - 错误 : implicit declaration of function `int open(...)' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43890160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com