Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program written to write 0xFF to all bytes within a given file.
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <limits>
- using namespace std;
- string filepath;
- int main()
- {
- cout << "Enter the directory of the file you wish to write to:\n"; //Ask for the directory
- cin >> filepath; //Store the directory in filpath
- ofstream file; //Set file as a file
- file.open (filepath,ios::in|ios::out|ios::binary|ios::trunc); //Open filepath in binary mode, with in/out, and truncating the existing text.
- long int * memory, *p, x; //Create memorycheck, memory, and p pointers
- memory = new long int[0]; //Request 1 byte of dynamic memory
- p = memory;
- x = &p;
- for (; x > 0; ); //Write 0xFF to the address P, move on to the previous byte, and repeat until beginning of file reached.
- {
- *p = 0xFF;
- x--;
- &p = x;
- }
- file << memory[p]; //Write all the newly overwritten memory to the file.. I think.
- cout << "0 written to all bytes. Press [Enter] to exit..\n"; //Displaying the finished message.
- std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); //Thanks, Duoas. xD..
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment