打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c++ 文件复制
userphoto

2014.03.25

关注

#include <fstream>   
using namespace std;  
int copyFile(char* sourceFile,char* newFile)  
{  
    ifstream in;  
    ofstream out;  
      
    in.open(sourceFile);  
      
    if (in.fail()) {  
        // 打开文件失败   
        cout << "打开文件失败" << endl;  
        in.close();  
        out.close();  
        return 0;  
    }  
  
    out.open(newFile);  
    if (out.fail()) {  
        cout << "打开文件失败" << endl;  
        in.close();  
        out.close();  
        return 0;  
    }  
      
    //开始复制   
    out << in.rdbuf();  
    out.close();  
    in.close();  
    return 1;  
}  

//主函数;复制文件
int main()  
{  
    char sourceFile[256];  
    char newFile[256];  
    cout << "请输入源文件:" << endl;  
    cin >> sourceFile;  
    cout << "请输入目标文件:" << endl;  
    cin >> newFile;  
      
    if (copyFile(sourceFile, newFile)) {  
        cout << "复制成功......." << endl;  
    }else  
    {  
        cout << "失败了, - -!" << endl;  
    }  
      
    return 0;  
}  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
用Windows API函数(CreateFile/ReadFile/WriteFile/CloseHandle)完成文件拷贝程序(初级版)
c++对文件的输入输出
178 f0603
0~9(int型)与‘0’~‘9’(char型)的转换
从文华财经Mytrader2009中读取数据 ? COS论坛 | 统计之都
c中读取Lua的全局变量数组
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服