P
pal
Hi all,
Could you help me how to use the fwrite( ) in C ++
Could you help me how to use the fwrite( ) in C ++
pal said:Could you help me how to use the fwrite( ) in C ++
Could you help me how to use the fwrite( ) in C ++
Pascal said:It's exactly the same as in C.
But is there a special reason for using fwrite instead of C++
streams (std:i|o)fstream) ?
James said:Masochism? Obfuscation?
Alp said:But is there a special reason for using fwrite instead of C++ streams
(std:i|o)fstream) ?
Pete said:No, you need std:: only if you use <cstdio>. If you use it *exactly* the
same as in C, with <stdio.h>, you use it *exactly* the same as in C,
with no namespace.
Juha said:Pete Becker wrote:
IIRC, the C++ standard doesn't define the header "stdio.h", only
"cstdio".
Alf said:In C++0x <cstdio> is allowed to bring the symbols into the global
namespace, as is the practice with current compilers, but which
undermines the whole scheme.
Juha said:I really can't understand why.
If the idea is to make a compromise with old code (why should a
compromise be made in the first place?), why not simply formalize the
<stdio.h> bringing all to the global namespace rather than break the
current convention of <cstdio> not doing so?
Speed. Some implementations of std:fstream::write() may
parallel the speeds of std::fwrite(), but many don't.
(And this is *only* for std:fstream::write(). Any of the
other functions of std:fstream will be hopelessly slower
than std::fwrite().)
I really can't understand why.
If the idea is to make a compromise with old code (why should a
compromise be made in the first place?), why not simply formalize the
<stdio.h> bringing all to the global namespace rather than break the
current convention of <cstdio> not doing so?
All this sounds crazy to me. It's like the standardization committee
is thinking like: "Hmm, it would be nice to deprecate <stdio.h> and
libraries inherited from C putting all into the global namespace, but
tons and tons of code out there is ignoring all this, using <stdio.h>
anyways, and assuming that everything is global. What should we do? I
know, let's keep <stdio.h> deprecated, but instead let's allow <cstdio>
to make everything global. That will work."
That sounds like the stupidest idea ever. It not only doesn't fix the
problem (ie. people using <stdio.h>), but completely nullifies the whole
idea of the std namespace and keeping the global namespace cleaner (at
least with respect to C library functions). It's like a "let's *not*
compromise with the *actual* problem, but instead let's break the
current modularity conventions."
James said:If speed's an issue, the best results can usually be had by
going down to the level of the system.
[email protected] said:Which is what fwrite() does. And it's much easier to use than system
calls.
Which is what fwrite() does. And it's much easier to use than
system calls.
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.