昨天晚上突然有的一个想法,现在拿出来试试。
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <dirent.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <iostream>
#define ERR_EXIT(m) \
do \
{ \
perror(m); \
exit(EXIT_FAILURE); \
}while(0)
int main()
{
char n;
int m = 1;
std::cout << "自毁程序启动..."<< std::endl;
std::cout << "请确认,确定输入Y,退出输入N" <<std::endl;
while(m)
{
std::cin >> n;
if(n == 'Y' || n == 'y')
{
system("rm pip.cpp a.out");
m--;
exit(0);
}else if(n == 'N' || n == 'n')
{
exit(0);
}
std::cout << "输入有误,请重新输入!!" <<std::endl;
}
return 0;
}
没有执行的结果。
执行后的结果:
有兴趣的可以玩玩。
pipp.cpp文件是我备份代码的。不要误会,要不然删除了,找不到代码了。