C语言 在追加模式下打开文件:使用 open() API
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7136416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening file in Append mode : using open() API
提问by JAY G
i am trying to open a file in append mode using open() api call , however following code is not working ! Its not writing anything to file! here is my code :
我正在尝试使用 open() api 调用以追加模式打开文件,但是以下代码不起作用!它没有向文件写入任何内容!这是我的代码:


回答by R.. GitHub STOP HELPING ICE
O_APPENDis not a mode by itself; it's a flag. Since the value of O_RDONLYis 0, it's like you're trying to open the file read-only but for append, which is nonsense. Use O_WRONLY|O_APPENDor O_RDWR|O_APPEND.
O_APPEND本身不是一种模式;这是一面旗帜。由于 的值为O_RDONLY0,这就像您试图以只读方式打开文件但用于追加,这是无稽之谈。使用O_WRONLY|O_APPEND或O_RDWR|O_APPEND。

