新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C++文件拷貝應(yīng)用技巧探討
C++編程語言中對于文件的操作是一個非常重要的應(yīng)用技術(shù)。我們在這篇文章中將會針對C++文件拷貝的相關(guān)應(yīng)用方式來具體講解一下這方面的應(yīng)用技巧,以便將來在實際編程中得到幫助。

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< < "沒有訪問權(quán)限!"< < endl;
- break;
- case CFileException::diskFull:
- cout< < "磁盤滿!"< < endl;
- break;
- default:
- cout< < "在文件拷貝過程中發(fā)生不知名錯誤!"< < endl;
- break;
- }
- }
- }
以上就是對C++文件拷貝的相關(guān)介紹。
【編輯推薦】
- C++ kmp算法模板代碼解讀
- C++ assert()函數(shù)應(yīng)用方式剖析
- C++ Memento模式應(yīng)用法則
- C++內(nèi)存對齊詳細使用指南
- C++常規(guī)DLL應(yīng)用方式介紹
分享文章:C++文件拷貝應(yīng)用技巧探討
標題鏈接:http://fisionsoft.com.cn/article/cdegeps.html


咨詢
建站咨詢
