C++读取二进制另存为

				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++宝典)