Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

here is my code

1)
long crcVal=22271827222;

tempFile<<hex<<crcVal;
same crcVal, i want to convert into ascii?
help me in this.

2)
long bufflength=1500;

tempFile<<bin<<bufflength // here it is not printing binary number ,some decimal value is printing in the file.

here i want to print the bufflength in binary number into the file.

please help me in this regard

thanks in advance

Bye
Posted
Updated 14-Aug-12 21:58pm
v2

Your filestream should be opened for binary writing.

see http://www.cplusplus.com/reference/iostream/fstream/fstream/[^]

so you should get something like this :
fstream
filestr ("test.bin", fstream::in | fstream::out | fstream::binary);
fstream << crcVal;
 
Share this answer
 
v2
Comments
JOYKAIGA1 15-Aug-12 3:31am    
its not test.bin file or a binary file.
its only a file with some extension.into that i have to write crcval in the binary number?
Philip Stuyck 15-Aug-12 3:39am    
ah sorry I misunderstood. you can test the same using cout.
so cout << hex << (int)5 << endl;
for example prints to the screen.
It should work though.
JOYKAIGA1 15-Aug-12 3:40am    
how about the binary number to print?
Philip Stuyck 15-Aug-12 3:44am    
you mean with 0 and 1 ?
there is no binary manipulator, check
http://www.cplusplus.com/reference/iostream/manipulators/
so you will have to convert to a binary string yourself.
an example how to this can be found here
http://www.cplusplus.com/reference/clibrary/cstdlib/itoa/
JOYKAIGA1 15-Aug-12 3:46am    
yes, with 0 and 1 only?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900