ifstream in("F:\\helloworld.exe"); size_t len = in.tellg(); char *oData = new char[len + 1]; in.seekg(0, ios::beg); in.read(oData, len); oData[len] = '\0'; printf("%d", sizeof(oData)); ofstream out("F:\\helloworld2.exe"); out.write((char *)oData, sizeof(oData)); out.close(); delete[] oData;
MODIFIED:
ifstream in(path); in.seekg(0, ios::end); size_t len = in.tellg(); unsigned char *oData = new unsigned char[len]; in.read((char*)(&oData[0]), len); in.close(); size_t counted = in.gcount(); cout << counted << endl; //result always 0 ??? printf("\n %d", len); //same amount as original file length ofstream out(newP); //myFile.open(newP, ios::out | ios::binary | ios::ate); out.write((char *)oData, len); out.close(); delete[] oData;
unsigned char
sizeof
len
sizeof(oData)
char
in.seekg(0, ios::beg); in.read(oData, len);
Eutherpy
ifstream in(original_path, ios::binary); ofstream out(clone_path, ios::binary); if (in.is_open() && out.is_open()) while (!in.eof()) out.put(in.get()); in.close(); out.close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)