ofstream overwrite

  • Thread starter Bernhard Hidding
  • Start date
B

Bernhard Hidding

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
 
S

Severin Ecker

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,169
Messages
2,570,920
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top