⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liunx_copyfiles.txt

📁 这是LINUX下文件复制的一个小例子,希望对学习linux下C语言编程的朋友有启发.
💻 TXT
字号:

#include <iostream>
#include <stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
using namespace std;
void mycopy(char *s,char *d)//定义mycopy函数实现拷贝 
{
    int fd1,fd2,nbytes;
 char buf[100];
 if((fd1=open(s,2))<0)//打开源文件 
 {perror("open file1.txt");
  exit(0);     
  }
 
 if((fd2=open(d,2))<0)//打开目标文件 
 {perror("open file2.txt");
 exit(0); 
  }
 
while((nbytes=read(fd1,buf,100))>0)//缓冲区读入源文件 
 {   write(1,buf,nbytes);//在显示器显示源文件内容 
     if(write(fd2,buf,nbytes)<0)//写入到目标文件 
   perror("write file2.txt");
  } 
 close(fd1);
 close(fd2);}
int main(void)
{ mycopy("file1.txt","file2.txt");
 system("PAUSE");	
 exit(1);}

⌨️ 快捷键说明

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