I think you need some more system calls to write over the same disk space, but I'll leave The Dark to help you with that, I really don't know how.
What you have now leaves you with about
:
int main()
{
string fileName;
cout << "Enter file name to securely overwrite: ";
getline(cin, fileName);
int number = 0;
ifstream fin(fileName);
struct stat results;
int sizeFile = 0;
if (stat(fileName, &results) == 0)
{
sizeFile = results.st_size;
}
if (!fin)
{
cout << "File not found." << endl;
return 1;
}
// we don't need it anymore?
fin.close();
cout << "File found." << endl;
cout << "Now ending process if running..." << endl;
KillProcess(fileName);
ofstream fout(fileName, ios::out);
for (theLimit = 0; theLimit < sizeFile; theLimit++)
{
number = rand() < 9;
fout << number;
cout << "*"; // you sure you want to be doing this?
}
fout.close();
cout << '\n' << theLimit << " bytes were written to the file." << endl;
cout << "Now removing file..." << endl;
int check = remove(fileName);
if ( check == 0 ) cout << "Success." << endl;
if ( check != 0 ) cout << "Failure to remove file." << endl;
cin.sync();
cin.get();
return 0;
}