473,586 Members | 2,652 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 1824
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_ostr eam<>::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_ostr eam<>::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.n etwrote:
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_ostr eam<>::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 objektorientier ter Datenverarbeitu ng
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
9840
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 | ios::binary) to declare a file object with read/write modes turned on for working with binary data. I've tried this and my file is not created. The only...
3
3478
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 possible to change the behavior of operator << so it will stream numeric values as their actual values when an ofstream is in binary mode. I did not,...
3
5483
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 that if the file is opened in something else than in binary mode. But in my example below, the file is really opened in binary.
8
4436
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 encode and then later decode. This is where I have a problem. I am using fopen, fscanf and fprintf for input output purposes. I know these are the...
49
61126
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
1779
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 read functions. -Siliconwafer
68
5197
by: vim | last post by:
hello everybody Plz tell the differance between binary file and ascii file............... Thanks in advance vim
14
2792
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 by df -k lopgod10:~/mycrfile # df -k /mnt/mvdg1/vset Filesystem 1K-blocks Used Available Use% Mounted on
9
7016
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 binary internal representation and not as pure text. What have I done wrong?
0
8202
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3837
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1449
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1180
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.