我无法复制整个二进制文件
I am not able to copy the entire binary file
ifstream ifile("/home/zuma/xps.mp3", ios::binary | ios::in);
ofstream ofile("/home/zuma/xxx.mp3", ios::binary | ios::out);
copy(istream_iterator<unsigned char>(ifile), istream_iterator<unsigned char>(), ostream_iterator<unsigned char>(ofile));
ifile.close();
ofile.close();
创建的新文件的字节数比原始文件少,文件不匹配
istream_iterator
使用operator>>
,这是空格分隔的(不,以二进制模式打开文件不会改变此行为)。 请改用istreambuf_iterator
。
istreambuf_iterator<char> in1(ifile), in2;
ostreambuf_iterator<char> out(ofile);
copy(in1, in2, out);
或者,正如 ildjarn 提到的,您可以用更少的键入来复制整个文件:
ofile << ifile.rdbuf();
相关文章:
- 正在读取二进制文件(is_open)
- 在C++中将类(带有Vector成员)保存为二进制文件
- 如何从二进制文件中读取字符串
- 保存/加载大量短数组到二进制文件
- 从二进制文件中读取整数数组
- Android 在编译二进制文件时重建静态库
- 在 C++ 中将双精度变量写入二进制文件
- clang 的 libFuzzer 可以在同一二进制文件中测试超过 1 个 API 吗?
- C++:实际上不是从二进制文件中读取
- 如何从二进制文件中的给定符号中获取调用程序图
- 将内部带有矢量的结构保存/读取到二进制文件中
- 如何使用位字段将数据从二进制文件复制到结构中?
- 停止和开始读取/复制二进制文件
- C 如何将二进制文件的一部分复制到新文件
- 将带有C++的二进制文件从 istream 复制到 ostream 并不总是正确的
- 有没有一种优雅的方法来读取二进制文件并将其内容复制到向量<int>
- 将二进制文件复制到C++中的远程位置
- 霍夫曼压缩读取文件不会复制二进制文件c++中的所有字节
- 我无法复制整个二进制文件
- 使用 ifsream 和字符串流复制二进制文件时出错