I have set up a transaction log to log different bank account transactions.
as my first menu choice option below is to print the log from the text file to console, is there a way of clearing the contents inside text file say if i choose option2?
// truncate.cpp
#include <fstream>
#include <iostream>
usingnamespace std;
int usage( ostream& outs, int result )
{
outs << "usage:\n"" truncate FILE ...\n\n""Zeros the named files.\n";
return result;
}
int main( int argc, char* argv[] )
{
if (argc == 1) return usage( cout, 0 );
for (int n = 1; n < argc; n++)
{
// Does file exist?
fstream f( argv[ n ], ios::in );
if (f)
{
// Yes, truncate it
f.close();
f.open( argv[ n ], ios::out | ios::trunc );
}
// No, or file could not be modified
if (!f)
cerr << "Could not truncate \"" << argv[ n ] << "\"\n";
// Close file (if open)
f.close();
}
return 0;
}