Potential bug with ofstream in linux
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Potential bug with ofstream in linux




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Potential bug with ofstream in linux  
s


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-12-04 03:38 PM

Can anyone verify this bug for me?

<Code>
#include <iostream>
#include <fstream>

using namespace std;

int main(void)
{
ofstream outfile;
outfile.open("data.txt", ios::out);
outfile.close();
}
</Code>

Attached is the data.txt.  When run, the data.txt file is zeroed-out
(has zero length).

Here are my versions numbers:

[sgray@sgray-pc]$ uname -a
Linux sgray-pc 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386
GNU/Linux

[sgray@sgray-pc]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --host=i386-redhat-linux --with-system-zlib
--enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)



Thanks,
Stephen






[ Post a follow-up to this message ]



    Re: Potential bug with ofstream in linux  
Paolo Carlini


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-12-04 03:38 PM

s wrote:
> Can anyone verify this bug for me?

Not a bug: according to Table 92 of the C++ Standard, the
'out' openmode corresponds to "w", as stdio equivalent,
which truncates to zero length (C99, 7.19.5.3, p3).

Paolo.





[ Post a follow-up to this message ]



    Re: Potential bug with ofstream in linux  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-12-04 03:39 PM

s <youshouldbe@home> writes:

> Can anyone verify this bug for me?
...
> Attached is the data.txt.  When run, the data.txt file is zeroed-out
> (has zero length).

That's exactly what one expects given your code.

What did *you* expect your code to do? Perhaps you meant to use
'ios::in' instead of 'ios::out'?

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.





[ Post a follow-up to this message ]



    Re: Potential bug with ofstream in linux  
Fletcher Glenn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-12-04 04:52 PM

Paul Pluzhnikov wrote:
> s <youshouldbe@home> writes:
>
> 
>
> ...
> 
>
>
> That's exactly what one expects given your code.
>
> What did *you* expect your code to do? Perhaps you meant to use
> 'ios::in' instead of 'ios::out'?
>
> Cheers,

Or could you have been thinking of ios::app which allows you
to append to the file.

--

Fletcher Glenn






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:18 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register