I am trying to write some information out to a file. I have a string in hex values and I need to write this out to the output file. The hex string I have is 4b70 4772 64. The string equivalent is KpGrd.

I have:

char a[] = "4b7047726400";

Then when I try to write it out to the output file it writes "4b7047726400" as a string and not hex values. I need it to be written as hex values where byte 1 woiuld be 4b, byte 2 would be 70, etc. Does it need to be converted to the string equivalent of KpGrd and then be written to the output file? Basically, when I open up the output file in a Hex editor I should see the first 6 bytes as 4b 70 47 72 64 and the string equivalent would be KpGrd. thanks.

You need to do some converting. Do some research on the std::hex stream manipulator for ideas.

Thanks I was able to figure it out.

Hmm, hex manipulator on the C language forum...
Be afraid of pure C fanatics ;)...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.