473,509 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question on file stream in binary mode

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

Apr 19 '07 #1
3 1820
shuisheng wrote:
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().
Apr 19 '07 #2
red floyd wrote:
shuisheng wrote:
>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().
Yes, all binary "mode" does is supress the mapping of \n into the
implementation specific new line sequence.
Apr 19 '07 #3
On Apr 19, 9:58 pm, Ron Natalie <r...@spamcop.netwrote:
red floyd wrote:
shuisheng wrote:
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().
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.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Apr 20 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9829
by: Brandon McCombs | last post by:
This may be the wrong group but I didn't see anything for VC++ so I'm trying here. I have a C++ book by Deitel and Deitel that says I can use fstream File("data.dat", ios::in | ios::out |...
3
3472
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
3
5466
by: Romain | last post by:
Hello, I am writing out a binary file. I figured that the number "10" is automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are line feed and carriage return. I know it does...
8
4422
by: Ritesh | last post by:
Hi!!!!!!!!!!! I am a final year engineering student. I am making a final year project on reed-solomon codec in C using VC++ 6.0. The input to the program can be any file that the user wants to...
49
61090
by: Sam | last post by:
Hi all, Is there a function in the standard library that can get the size of a file? Thank you very much. Sam.
8
1773
by: siliconwafer | last post by:
Hi All, If I open a binary file in text mode and use text functions to read it then will I be reading numbers as characters or actual values? What if I open a text file and read it using binary...
68
5156
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
14
2779
by: prasadjoshi124 | last post by:
Hi All, I am writing a small tool which is supposed to fill the filesystem to a specified percent. For, that I need to read how much the file system is full in percent, like the output given...
9
7009
by: Hatzigiannakis Nikos | last post by:
I have written the following code in DEV C++ but the produced file is a normal text file (you can type it in command line). I was expecting that the numeric values would have written in their...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.