如何在二进制文件中附加二进制文件C++
How to append binary file with a binary file in C++
我有两个二进制文件,我想将一个与另一个一起附加。我该怎么做?
std::ofstream outFile;
outFile.open( "file.bin", ? );
巢线应该是什么?
有一个行
:std::ofstream outFile("file.out", std::ios::ate );
std::ifstream inFile( "file.in" );
std::copy(
(std::istreambuf_iterator<char>(inFile)), // (*)
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(outFile)
);
(*) 额外的一对括号,以防止将其解析为函数声明。
为了获得更好的性能,您可以使用ifstream::read
分块读取文件,并使用ofstream::write
写入它们。
这不是最理想的,但您可以尝试如下方法:
std::ofstream outFile( "file.bin", ios_base::app | ios_base::out );
std::ifstream inFile(source_file_name, ios_base::binary | ios_base::in);
source >> noskipws;
char c;
while (inFile >> c) {
outFile << c;
}
您可以通过使用更大的缓冲区来提高效率。
相关文章:
- 正在读取二进制文件(is_open)
- 在C++中将类(带有Vector成员)保存为二进制文件
- 如何从二进制文件中读取字符串
- 保存/加载大量短数组到二进制文件
- 从二进制文件中读取整数数组
- Android 在编译二进制文件时重建静态库
- 在 C++ 中将双精度变量写入二进制文件
- clang 的 libFuzzer 可以在同一二进制文件中测试超过 1 个 API 吗?
- C++:实际上不是从二进制文件中读取
- 如何从二进制文件中的给定符号中获取调用程序图
- 将内部带有矢量的结构保存/读取到二进制文件中
- 编译多个C++文件.调用二进制文件以运行代码
- 如何使用位字段将数据从二进制文件复制到结构中?
- uint8_t同一二进制文件的不同十进制值
- C++单个生成文件多个二进制文件
- 尝试将数字写入二进制文件时引发异常
- C++中读/写二进制文件
- 如何忽略某些二进制文件的执行?
- 对在不同二进制文件中创建的对象文件的依赖关系
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作