linux下文件的读

来源:互联网 发布:美工刀片可以过安检吗 编辑:程序博客网 时间:2024/06/18 06:47
 自己写的
  //copy1.cc  #include <iostream>  #include <fcntl.h>  #include <sys/types.h>  #include <sys/stat.h>  #include <unistd.h>    using namespace std;  int main()  {    string filename="/mnt/hgfs/temp/hello/test.dat";char* p=(char*)filename.c_str();  if(access(p, F_OK) != 0)    {    cout << "file not found......" << endl;    return 0;    }    int fin = open(p, O_RDONLY, 0777);  char buff[1024] = {'\0'};    int len = 0;  while((len = read(fin, buff, sizeof(buff))) > 0)  {     for(int i=0;i<len;i++)   cout<<buff[i];  }    close(fin);    return 0;    }  

原创粉丝点击