当前位置:首页 >> 编程开发 >> Visual C++ >> 内容

c++文件拷贝

时间:2011/6/4 作者:平凡之路 来源:xuhantao.com 浏览:

#include<iostream.h>
#include<afx.h>
void main()
{
  char SourceName[81];
  char DestinName[81];
  cout<<"n 请输入源文件名:";
  cin>>SourceName;
  cout<<"n 请输入目标文件名:";
  cin>>DestinName;
  try
  {
    CFile fileSource(SourceName,Cfile::modeRead);
    CFile fileDestin(DestinName,Cfile::modeCreate|Cfile::modeWrite);
    char c;
    while(fileSource.Read(&c,1))
      fileDestin.Write(&c,1);
  }
  catch(CFileException *e)
  {
    switch(e->m_cause)
    {
    case CFileException::fileNotFound:
      cout<<"未找到文件!"<<endl;
      break;
    case CFileException::badPath:
      cout<<"路径输入有错!"<<endl;
      break;
    case CFileException::accessDenied:
      cout<<"没有访问权限!"<<endl;
      break;
    case CFileException::diskFull:
      cout<<"磁盘满!"<<endl;
      break;
    default:
      cout<<"在文件拷贝过程中发生不知名错误!"<<endl;
      break;
    }
  }
}

相关文章
  • 没有相关文章
  • 徐汉涛(www.xuhantao.com) © 2024 版权所有 All Rights Reserved.
  • 部分内容来自网络,如有侵权请联系站长尽快处理 站长QQ:965898558(广告及站内业务受理) 网站备案号:蒙ICP备15000590号-1