尝试使用posix命令在c++
我目前有此代码,我需要使用标准POSIX调用将文本写入文件:
file = open(filename, O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
if (file == -1) {
perror("File cannot be opened");
return -1;
}
但是,每次运行时,我都会获得权限拒绝错误: 无法打开文件:拒绝许可
我尝试在线找到一些东西,并找到此“ cl oper()函数中的权限”在c 中 但是,在尝试这些建议时,我会遇到同样的问题,如果是因为我在使用C+ C for参考时,我正在使用C ++,我正在Mac上,并且正在通过IDE(CLION)运行它,
请提供帮助!
I currently have this code where I need to use standard POSIX calls to write text to a file:
file = open(filename, O_CREAT | O_RDWR | O_APPEND, S_IRUSR | S_IWUSR);
if (file == -1) {
perror("File cannot be opened");
return -1;
}
However, every time I run it, I get the permission denied error:File cannot be opened: Permission denied
I tried finding something online and found this "Permission denied" in open() function in C
but when trying those suggestions, I get the same issue and idk if it's because I am using C++ while they were using C. For reference, I am on a Mac and am running this through an IDE (CLion)
please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论