C++文件拷貝應(yīng)用技巧探討
作者:佚名
在這篇文章中,我們將會(huì)通過(guò)一段代碼的解讀充分講解一下有關(guān)C++文件拷貝的應(yīng)用方法,希望初學(xué)者可以從中掌握這一應(yīng)用技巧。
C++編程語(yǔ)言中對(duì)于文件的操作是一個(gè)非常重要的應(yīng)用技術(shù)。我們?cè)谶@篇文章中將會(huì)針對(duì)C++文件拷貝的相關(guān)應(yīng)用方式來(lái)具體講解一下這方面的應(yīng)用技巧,以便將來(lái)在實(shí)際編程中得到幫助。
C++文件拷貝代碼示例:
- #include< iostream.h>
- #include< afx.h>
- void main()
- {
- char SourceName[81];
- char DestinName[81];
- cout< < "\n 請(qǐng)輸入源文件名:";
- cin>>SourceName;
- cout< < "\n 請(qǐng)輸入目標(biāo)文件名:";
- 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< < "路徑輸入有錯(cuò)!"< < endl;
- break;
- case CFileException::accessDenied:
- cout< < "沒(méi)有訪問(wèn)權(quán)限!"< < endl;
- break;
- case CFileException::diskFull:
- cout< < "磁盤(pán)滿!"< < endl;
- break;
- default:
- cout< < "在文件拷貝過(guò)程中發(fā)生不知名錯(cuò)誤!"< < endl;
- break;
- }
- }
- }
以上就是對(duì)C++文件拷貝的相關(guān)介紹。
【編輯推薦】
責(zé)任編輯:曹凱
來(lái)源:
博客園