file.cc

来自「达内IT培训Unix C++第一天源码 是入门Unix 下C++编程的好东西」· CC 代码 · 共 26 行

CC
26
字号
#include <iostream>using namespace std;#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <unistd.h>#include <cstring>int main(){	char* username = getlogin();	if(strcmp(username,"openlab")==0){		cout << "别捣乱啦" << endl;		return 0;	}	int fd = open("luck",O_WRONLY|O_CREAT|O_EXCL, 0644);	if(fd<0){		cout << "失败!" << endl;		return -1;	}	cout << "成功!" << endl;	write(fd, username, strlen(username)); 	close(fd);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?