This is the mail archive of the gcc-help@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: ios::ate in gcc3.4.2


Hi Li Qihong,

Do this...
------------------------------
#include <iostream>
#include <fstream>

using std::fstream;
using std::ios_base;

int main()
{
    fstream f;
    f.open("1", ios_base::in | ios_base::out | ios_base::ate);
//  f.seekp(0, ios_base::end); -- unnecessary w/ios_base::ate
    f << "Haha";
    f.close();
}
---------------------------------

You didn't specify the ios_base::in, which will prevent the ios_base::out from performing an ios_base::trunc for you.

Alternatively, you could do...

f.open("1", ios_base::out | ios_base::app);

...the ios_base::ate is redundant.

Please see p639 of Stroustrup's C++ Programming Language (special edition).

HTH,
--Eljay


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