0

I created a file with the flag O_CREAT, but when I tried to open the created "out.txt" with Notepad. It said "cannot open this file" or something like "access denied".

fd = open("out.txt", O_CREAT);
4

1 回答 1

4

您必须使用close-call 关闭文件。否则它的内容不会被刷新并且文件不会被写入磁盘。此外,您可能会告诉您要在文件上做什么。

fd = open("out.txt", O_WRONLY | O_CREAT); //write to the file
//write to file
close(fd); //might check return value

参见维基百科

于 2013-04-21T13:19:54.303 回答