C++输出输入流复制文件
2015-01-03 09:53
281 查看
C++输入输出流方式复制文件。
// stream.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <fstream> #include <iostream> using namespace std; int main( ) { ofstream outfile; outfile.open("d:/2.jpg", ios::binary); ifstream infile; infile.open ("c:/1.jpg", ios::binary ); infile.seekg (0, ios::end); long length = infile.tellg(); infile.seekg (0, ios::beg); const int BufferSize = 100; char buffer[BufferSize]; while(1) { memset(buffer,0,sizeof(buffer)); infile.read (buffer,BufferSize);//从文件流中读取数据到buffer中 outfile.write(buffer,sizeof(buffer)); int curPos = infile.tellg(); printf("read->"); if (-1==curPos){ break; } } return 0; }
相关文章推荐
- 输入流与输出流:C++中打开文件的方式
- 使用基本字节输入流,字节输出流一次读写一个字节来复制文本 文件
- 使用缓冲输入流和缓冲输出流复制文件
- 未能将临时文件复制到输出目录 无法将*.dll文件复制到运行目录。
- C++中的文件输入/输出(5):二进制文件的处理
- C++中文件的输入输出
- C++中的文件输入/输出(4):检测输入/输出的状态标志
- C++中的文件输入/输出
- 利用C++标准符号,把调试信息输出到文件
- 未能将临时文件复制到输出目录中
- 把命令行参数中的前一个文件名标识的文件, 复制到后一个文件名标识的文件中, 如命令行中只有一个文件名则把该文件写到标准输出文件(显示器)中
- C++中的文件输入/输出(1):你的第一个程序
- C++中的文件输入/输出ios:xx eat Processing(zz)
- C++复制文件的代码
- C++复制文件(使用WindowsAPI)
- C++中文件的输入输出
- C++中的文件输入/输出
- 【转】c++文件复制
- C++中的文件输入/输出(6):一些有用的函数
- C++中的文件输入/输出(3):掌握输入/输出流