std::string filename2 = "D:\\Tcpview.txt";
//fstream fin;
ifstream fin(filename2, ios::in | ios::binary);
//fin.open(filename2.c_str());
if(!fin)
{
cerr<<"open error!"<<endl;
return;
}
//获取二进制文件的长度
fin.seekg(0,ios::end);
int len = fin.tellg();
char *f= new char[len];
fin.seekg(0,ios::beg);
char *tmp = new char[len+1];
fin.read(tmp, len);
ofstream ofile; //定义输出文件
ofile.open("d:\\sokit2.txt", ios::out | ios::binary); //作为输出文件打开
ofile.write(tmp, len);
fin.close();
ofile.close();
C++读取二进制另存为
最新推荐文章于 2022-12-13 12:03:25 发布