Question on file stream in binary mode

S

shuisheng

Dear All,

I have question on file stream. I'd like the operator << to read and
write a variable in binary mode? For example,

#include <iostream>

int main()
{
ofstream f("output.dat");
double d = 3.1415926;
f << d; // I want d is written in binary mode. But here it is
written formatedly.
return 1;
}

Thanks,
Shuisheng
 
R

red floyd

shuisheng said:
Dear All,

I have question on file stream. I'd like the operator << to read and
write a variable in binary mode? For example,

#include <iostream>

int main()
{
ofstream f("output.dat");
double d = 3.1415926;
f << d; // I want d is written in binary mode. But here it is
written formatedly.
return 1;
}

the "<<" operator is for formatted output. Look at
std::basic_ostream<>::write().
 
R

Ron Natalie

red said:
the "<<" operator is for formatted output. Look at
std::basic_ostream<>::write().

Yes, all binary "mode" does is supress the mapping of \n into the
implementation specific new line sequence.
 
J

James Kanze

Yes, all binary "mode" does is supress the mapping of \n into the
implementation specific new line sequence.

You know better than that. Binary mode suppresses an
implementation defined mapping of the '\n' and EOF, both of
which can be represented in many different ways on different
systems.

Under Windows, in text mode, '\n' maps to the two character
sequened 0x0D,0x0A, and '\x1A' is recognized as an EOF. But
that's a particularity of Windows; other systems have different
rules.
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,224
Latest member
BettieToom

Latest Threads

Top