开放写入前清除文件() [英] Clear file before writing with open()
本文介绍了开放写入前清除文件()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用的fopen
,将其设置为是W
将自动清除该文件对我来说。不过现在我试图做同样的事情打开
,
With fopen
, by setting it to w
will automatically clear the file for me. However now I'm trying to do the same thing with open
,
int file = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
这并不能保证该文件是空的,在开始写的(?)。我怎样才能做到这一点?
This won't guarantee that the file is empty and write at the beginning(?). How can I achieve that?
推荐答案
添加 O_TRUNC
- 初步明确从文件中的所有数据
Add O_TRUNC
- Initially clear all data from the file.
这篇关于开放写入前清除文件()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文