Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copy a file
- #include <fstream> // std::ifstream, std::ofstream
- int main () {
- std::ifstream infile ("test.txt",std::ifstream::binary);
- std::ofstream outfile ("new.txt",std::ofstream::binary);
- // get size of file
- infile.seekg (0,infile.end);
- long size = infile.tellg();
- infile.seekg (0);
- // allocate memory for file content
- char* buffer = new char[size];
- unsigned ii[5] = {0x23, 0x23, 0x23, 0x23, 0x23};
- // read content of infile
- infile.read (buffer,size);
- // write to outfile
- //outfile.write (buffer,size);
- outfile.write ((char*)ii,sizeof(ii));
- // release dynamically-allocated memory
- delete[] buffer;
- outfile.close();
- infile.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment