![](/img/trans.png)
[英]How can I read and write from files using the headers fcntl.h and unistd.h?
[英]How to write in file in append mode using fcntl.h
下面是我的代码:
#include <iostream>
#include <fcntl.h>
#include <unistd.h>
using namespace std;
int main()
{
int filedesc = open("testfile.txt", O_RDWR | (O_APPEND |O_CREAT) ,S_IRWXO);
if (filedesc < 0) {
cout<<"unable to open file";
return -1;
}
if (write(filedesc, "This will be output to testfile.txt", 36) != -1) {
cout<<"writing";
close( filedesc );
}
return 0;
return 0;
}
如果我第二次以上运行相同的o / p是“无法打开文件”。 难道我做错了什么?
这是权限问题
尝试改变
S_IRWXO
至
S_IRWXU
会很好的
S_IRWXO
他人阅读,编写,执行/搜索
参考http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysstat.h.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.