程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> 關於C++ >> c++文件拷貝

c++文件拷貝

編輯:關於C++

#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;
    }
  }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved