473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

writing 10 gives 10 and 13

I am trying to write numbers to a binary file. The problem that I have is when I try to write a 10 it is preceded by a 13. I believe that this has something to do with the program thinking that I want to put in a return.

When I write:

newFile.put(26);
newFile.put(10);
newFile.put(0);

and hex dump. The result is:
1A 0D 0A 00
That 0D shouldn't be there.

Is there a better way to write numbers to file or a way to stop this from happening? Also I need the numbers in this order since a different program will be using the file.
Jul 30 '09 #1
4 1399
Savage
1,764 Expert 1GB
@thepenguin77
I'll assume that you are using ofstream objects, if so put takes a char as a argument,not an int.If you have opened your file in binary mode,just use << operator to write your data into the file.

,kind regards
Jul 30 '09 #2
Ok, So I would use
newFile << 26 << 10 << 0;

And I'm using fstream if it makes a difference.

Edit: It didn't work, I opened it with ios::binary and when I used << it just put the ascii code in the file.
Jul 30 '09 #3
JosAH
11,448 Expert 8TB
@thepenguin77
The operator<< formats the values you write; use the put() or the write() functions for unformatted output. Have a look here.

kind regards,

Jos
Jul 30 '09 #4
I found the problem. When I was using write() and put() I didn't have it set to binary.
Jul 30 '09 #5

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

Similar topics

40
by: post400 | last post by:
Hi, there is another famous book 'Writing solid code' but does it apply to Python ? Or it's usable only by Microsoft C programmers ? The author seems to be an ex-Microsoft guy ! Thanks ,...
9
by: wordsender | last post by:
Hey guys, I can't figure this one out, why is this simple script giving me problems? logfile=file(r'test.txt','w') logfile.write('datetime') test=logfile.readlines() When I run it I get...
3
by: Ian Davies | last post by:
Hello I have the following code which changes directory, creates a file and then writes rows to it. It works fine except the file is created in the folder the php script is in instead of the...
15
by: Douglas Garstang | last post by:
All, I posted a newsgroup question here a few weeks back, asking some questions that related to my 10 year quest (so far) to understand pointers. Someone suggested I write a simple emulator....
4
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
2
by: simonc | last post by:
Is there an easy way of writing a number in 32 bit integer format into four bytes of a file? I am experimenting with FilePut but I can only make it work by defining a four byte array and doing some...
12
by: Chris Springer | last post by:
I'd like to get some feedback on the issue of storing data out to disk and where to store it. I've never been in a production environment in programming so you'll have to bear with me... My...
89
by: Skybuck Flying | last post by:
Hello, This morning I had an idea how to write Scalable Software in general. Unfortunately with Delphi 2007 it can't be done because it does not support operating overloading for classes, or...
6
by: Gilly | last post by:
Hi I am trying to create an application that uses some form of input to create a midi file. I would like for this to be a 'real time' process. In other words, I want to be able to begin playing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.