Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual c++ 使用c++;代码_Visual C++_Networking - Fatal编程技术网

Visual c++ 使用c++;代码

Visual c++ 使用c++;代码,visual-c++,networking,Visual C++,Networking,我试图写一个代码,应该能够使任何格式的文件副本。目前,我正在尝试.pdf格式。以下是我编写的代码: #include <iostream> #include <fstream> using namespace std; int main() { ifstream in("a.pdf", ios::binary); if(in.fail()) { cout<<"\nThe file couldn't be opened\n"; exit(0);

我试图写一个代码,应该能够使任何格式的文件副本。目前,我正在尝试.pdf格式。以下是我编写的代码:

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream in("a.pdf", ios::binary);
if(in.fail())
{
    cout<<"\nThe file couldn't be opened\n";
    exit(0);
}

ofstream out("b.pdf", ios::binary);

while(!in.eof())
{
    char buf[1000];
    in.read(buf, sizeof(buf));
    out<<buf;
}
in.close();
out.close();
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
ifstream-in(“a.pdf”,ios::binary);
if(in.fail())
{

cout我认为发生这种情况是因为您使用的是
operatorYeah,它在使用out之后工作得非常好。write(buf,size(buf)),而不是out
while(!in.eof())
{
    char buf[1000];
    in.read(buf, sizeof(buf));
    out.write(buf, sizeof(buf));
}