博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 文件复制
阅读量:7055 次
发布时间:2019-06-28

本文共 1262 字,大约阅读时间需要 4 分钟。

1 #include
2 #include
3 4 void copy(char* src, char* dst); 5 int main() 6 { 7 using namespace std; 8 char src[50] = "E:/test/jdk-8u121-windows-x64.exe"; 9 char dst[50] = "E:\\test\\jdk-8u121-windows-x64_bak.exe";10 copy(src, dst);11 12 return 0;13 }14 15 void copy(char* src, char* dst)16 {17 using namespace std;18 ifstream in(src,ios::binary);19 ofstream out(dst,ios::binary);20 if (!in.is_open()) {21 cout << "error open file " << src << endl;22 exit(EXIT_FAILURE);23 }24 if (!out.is_open()) {25 cout << "error open file " << dst << endl;26 exit(EXIT_FAILURE);27 }28 if (src == dst) {29 cout << "the src file can't be same with dst file" << endl;30 exit(EXIT_FAILURE);31 }32 char buf[2048];33 long long totalBytes = 0;34 while(in)35 {36 //read从in流中读取2048字节,放入buf数组中,同时文件指针向后移动2048字节37 //若不足2048字节遇到文件结尾,则以实际提取字节读取。38 in.read(buf, 2048); 39 //gcount()用来提取读取的字节数,write将buf中的内容写入out流。40 out.write(buf, in.gcount()); 41 totalBytes += in.gcount();42 }43 in.close();44 out.close();45 }

 

转载于:https://www.cnblogs.com/endenvor/p/6819043.html

你可能感兴趣的文章
ThinkPHP配置简单的mysql读写分离
查看>>
AngularJS Select(选择框)
查看>>
EXT.NET入门必读
查看>>
数据结构定义
查看>>
实验报告二201521460014
查看>>
sql中的Replace
查看>>
POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏...
查看>>
A. Karen and Morning
查看>>
虚拟内存和虚拟地址空间理解(转载)
查看>>
[LeetCode] Pow(x, n) 二分搜索
查看>>
简记mysql中文乱码(插入变成??)的问题.
查看>>
C# 科学计数法转换成数字
查看>>
深入理解:java类加载器
查看>>
Android Studio使用Git版本控制github
查看>>
跳转到移动终端
查看>>
kubernetes 简介
查看>>
JQuery实例
查看>>
c++编程命名规范
查看>>
时间戳格式化
查看>>
背景建模技术(六):帧处理(FrameProcessor)模块
查看>>