473,511 Members | 14,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing byte characters to a binary ofstream

1 New Member
I'm trying to write binary data to a file. I want to create a file that contains the following data (hexadecimal notation):
80
So I tried this:
Expand|Select|Wrap|Line Numbers
  1.     ofstream outFile("file.txt", ios::binary);
  2.     uint32_t character = 0x80;
  3.     outFile << character;
  4.  
  5.     outFile.close();
Instead, I got...
3132 380a
What am I doing wrong?
Oct 2 '11 #1
1 3197
weaknessforcats
9,208 Recognized Expert Moderator Expert
YOu need to use outfile.write rather than operator<< for binary. The << writes only text.
Oct 2 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1592
by: Vincent Zhu | last post by:
I moved ASP WebPages from Windows 2000 server to Windows 2003 server platform. Those double-byte characters (Japanese) retrieved from SQL server 2000 are corrupted. I am using Macromedia...
2
7793
by: phyzics | last post by:
I am porting an application from C++ to C#, and am having trouble finding a way to quickly and efficiently write structures to a binary file. In C++ this is trivial because all that is necessary is...
4
16903
by: Gidi | last post by:
Hi, i have a byte array, and i'm writing it to a file, i want to start a new line, how can i do it? (like WriteLine in StreamWriter) I'm using FileStream: FileStream fs = new...
1
1986
by: Indian | last post by:
Using VC++, how can i display multi byte characters like japanese,chineese etc in the MFC control CEdit. Please give me the solution immediately.. It's urgent
10
2862
by: Thorsten Ottosen | last post by:
Hi, I'm trying to escape html before its saved in a database. I tried $text = htmlentities( $reader->value ); but that don't work for e.g. japanese characters.
4
1640
by: Bob Cummings | last post by:
Good Day I would like to write a password to a binary file. I am following along in the book and examples I have found googling. However when I open the file in notepad it looks like a text...
198
5109
by: Antoninus Twink | last post by:
Or, just how low has this group sunk? Twice in the past couple of days, Default Loser has accused Chris Hills, member of the ISO C committee, of being a troll (though given that the former's...
5
3794
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
1
4396
MrPickle
by: MrPickle | last post by:
I am tokenizing a string and sending it to a ofstream but I am getting strange results. The \n sequence isn't working; it doesn't go to a new line. I'm getting Chinese/Japanese characters in the...
0
1014
by: Lamont J | last post by:
'Reading file Byte-by-Byte Dim Rs As Byte = bReader.ReadByte() 'Converting Byte To Integer Dim n As Integer = CType(Rs, Integer) 'Function Input Integer (0-255) Function a(byval n as...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7432
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...
1
7093
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...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
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,...
0
4743
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
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.