/*
* main.cpp
*
* Created on: 2024-6-9
* Author: root
*/
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int f;
const char *f_path="test";
mode_t f_attrib;
f_attrib=S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP |
S_IROTH;
f=open(f_path,O_RDONLY);
if(f==-1)
{
f=open(f_path,O_RDWR | O_CREAT,f_attrib);
if(f!=-1)
puts("create one new file!");
else
{
puts("can't create new file,program exit");
return 1;
}
}
else
puts("file open success!");
close(f);
return 0;
}
y运行:
文章评论(0条评论)
登录后参与讨论