[英]Copy a certificate file to another location
I have a .crl file which I want to copy to another location. 我有一个.crl文件,我想复制到另一个位置。 From all the posts which I have seen till now, it can't be done without copying the contents. 从我到目前为止看到的所有帖子中,如果不复制内容就无法完成。 Is there any method in which I can transfer the file to another location in cpp without copying the contents? 有什么方法可以在不复制内容的情况下将文件传输到cpp中的另一个位置?
I tried by copying the contents by using the usual fopen method. 我尝试使用通常的fopen方法复制内容。 But the data was not being written to the buffer . 但是数据没有被写入缓冲区。 If there is no direct method, could anyone please tell me how to read the certificate file and write the contents to another file in a different location? 如果没有直接方法,谁能告诉我如何读取证书文件并将内容写入另一个位置的另一个文件中?
I have also tried the fstream methods 我也尝试了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";
But it displayed the errors: error opening input file reading from file failed writing to file failed 但是它显示了错误:打开输入文件从文件读取失败,写入文件失败
Thank you in advance 先感谢您
See, this might help you. 看,这可能对您有帮助。 As you do not want to read, I thought you do not want to perform read and write operation yourself. 由于您不想阅读,我以为您不想自己执行读写操作。
#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);
}
Based on your response, I write another answer. 根据您的回答,我写另一个答案。
For Window, there is function [CopyFile][1]
. 对于Window,具有功能[CopyFile][1]
。 You can use this function to copy the file without reading the content by yourself. 您可以使用此功能复制文件,而无需自己阅读内容。
For linux/unix based, I am unable to find the direct equivalent of CopyFile
. 对于基于linux / unix的应用程序,我无法找到CopyFile
的直接等效项。
I believe that this question might help you. 我相信这个问题可能会对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.