This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: ios::ate in gcc3.4.2
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Li Qihong <liqh at hed dot com dot cn>, gcc-help at gcc dot gnu dot org
- Date: Wed, 22 Dec 2004 06:50:09 -0600
- Subject: Re: ios::ate in gcc3.4.2
- References: <41C8E760.FAC57CA6@hed.com.cn>
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