By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,853 Members | 1,541 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,853 IT Pros & Developers. It's quick & easy.

ofstream overwrite

P: n/a
Hello,
my program writes an array into a file using the following code:

ofstream arrayfile;
arrayfile.open("array_file.dat");
....
arraydatei.close();

This works as long as the file does not exist before I run the program. If
the file already exists the program does not overwrite it with new data, but
does nothing. I am using g++ on SuSE 9.1. It seems that the default on my
system is NOT to overwrite an existing file. How do I specifiy that an
existing file should be overwritten? Probably by using the ios_base:: flag
in a proper way?
Thanks in advance,
Bernhard Hidding


Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
hi!
ofstream arrayfile;
arrayfile.open("array_file.dat");
...
arraydatei.close(); hmm,.. mothertongue bites back ;]
this should be arrayfile;
Probably by using the ios_base:: flag in a proper way?

try using ios_base::trunc explicitly when opening,.. though this should be
used by default anyway as far as i know...
are you sure, you have the correct rights on the file for truncating it?

regards,
sev
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.