#include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> #include <fcntl.h> char data [ 6 ]; main ( ) { int len; desc = open ( "Resultat",O_WRONLY | O_CREAT | O_EXCL,0666 ); if ( desc != -1 ) { len = write ( desc,&data,sizeof ( data ) ); if ( len != sizeof ( data ) ) printf ( "ERROR" ); } }
O_WRONLY undeclared (first use in this function) O_CREAT undeclared (first use in this function) O_EXCL undeclared (first use in this function)
我该如何解决这个问题?
解决方法
@Kevin是对的.在我的Arch安装中,根据
man fcntl.h
,你需要#include< fcntl.h>获得对O_WRONLY的访问权限.
要使用open(),还需要#include< sys / stat.h>.