尝试使用posix命令在c++

发布于 2025-01-25 09:26:17 字数 724 浏览 2 评论 0原文

我目前有此代码,我需要使用标准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 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文