This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fstream behaviour error / wrong installation ?


Stephane MILLET wrote:

Hope I'm on the right list for this kind of problem, if not sorry.

Not really: gcc-help is more suited. This one is for discussion about the development of gcc itself.

My problem: i wrote the following very simple program, but...

Your installation is ok, but you are using fstreams incorrectly.


According to Table 92 of the ISO Standard, the stdio equivalent
of the ofstream default open mode (ios::out) is "w". You need
either "a" or "r+" in order to add more data. I suggest using an
fstream the first time and passing ios::out | ios::app (| ios::ate)
the second time. Also, beware that you cannot portably reopen a
fstream without a clear in time middle:

http://gcc.gnu.org/onlinedocs/libstdc++/faq/index.html#4_4_iostreamclear

(but your cool GNU C++ library works well anyway ;)

Paolo.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]