gpt4 book ai didi

c++ - 将证书文件复制到另一个位置

转载 作者:行者123 更新时间:2023-11-30 17:45:12 33 4
gpt4 key购买 nike

我有一个 .crl 文件,我想将其复制到另一个位置。从我目前看到的所有帖子来看,如果不复制内容是不可能完成的。有没有什么方法可以将文件传输到 cpp 中的另一个位置而不复制内容?

我尝试使用通常的 fopen 方法复制内容。但数据并未写入缓冲区。如果没有直接的方法,谁能告诉我如何读取证书文件并将内容写入不同位置的另一个文件?

我也尝试过fstream方法

std::ofstream dest("destination.crl", std::ios::trunc|std::ios::binary);

if(!dest.good())
{ std::cerr << "error opening output file\n";
//std::exit(2);
}
std::fstream src("sourcec.crl", std::ios::binary);
if(!src.good())
{ std::cerr << "error opening input file\n";
//std::exit(1);
}
dest << src.rdbuf();
if(!src.eof()) std::cerr << "reading from file failed\n";
if(!dest.good()) std::cerr << "writing to file failed\n";

但它显示错误:打开输入文件时出错读取文件失败写入文件失败

提前谢谢

最佳答案

我找到了这个here .

看,这可能对你有帮助。由于您不想阅读,我以为您不想自己执行读写操作。

#include <istream>
#include <iostream>
#include <fstream>
#include <iterator>


using namespace std;


int main()

{

fstream f("source.crl", fstream::in|fstream::binary);
f << noskipws;
istream_iterator<unsigned char> begin(f);
istream_iterator<unsigned char> end;

fstream f2("destination.crl",
fstream::out|fstream::trunc|fstream::binary);
ostream_iterator<char> begin2(f2);

copy(begin, end, begin2);
}

关于c++ - 将证书文件复制到另一个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19705849/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com