File Writing problem in Visual C++

This is one of the function in my C++ code, this code writes into ascii values rather than binary values. Also I have tried it on other compiler like eclipse too, the values of buf are written in ascii values. I have a hex reader which helps me to read the data from this file.

counter(okCFrontPanel *xem)
{
unsigned char buf[2048];
//long int len;
int des_done;
std::ofstream f_out (“Oct6.text”, std::ios::binary || std::ios::app );
std::ofstream file_out;

if (false == f_out.is_open()) {
	printf("Error: Output file could not be opened.\n");
	return(false);
}	xem-> SetWireInValue(0x00, 0xffff, 0xffff); 
	xem -> UpdateWireIns(); // RESET
	xem-> SetWireInValue(0x00, 0x0000, 0xffff); 
	xem-> UpdateWireIns();   
	
xem-> ActivateTriggerIn(0x40, 0);

for(int i = 0; i < 1 ; i ++ ){
	xem-> ActivateTriggerIn(0x41, 0);

printf("\nFirst time read\n");
des_done=0;
while (des_done==0) {
	xem -> UpdateTriggerOuts();
	des_done = xem->IsTriggered(0x60, 0x0001);
}
// Pull decrypted data out
int j;
xem -> ReadFromPipeOut(0xa1,1024,  buf);
for(j =0; j,j);
f_out.write((char*)buf, 1024);
}
f_out.close();
return(true);

}

This is the ouput of my oct6 file:
@??C?Pc?p ??? C??? @p*0???*p@ ?? @p*?? ??? ??0??? @p*?? ??? ??04Vx???? @? @p??? ??? 0???P???????????????? @p*0???p@ ?? @p?? ??? ??0 ???? @p*?? ??? ??04Vx?*??? @? @p*???? ??? 0???? P??? @p*0???*p@ ?? @p*?? ??? ??0??? @p*?? ??? ??04Vx???? @? @p??? ??? 0???P???????????????? @p*0???p@ ?? @p?? ??? ??0 ???? @p*?? ??? ??04Vx?*??? @? @p*???? ??? 0???? P??? @p*0???*p@ ?? @p*?? ??? ??0??? @p*?? ??? ??04Vx???? @? @p??? ??? 0???P???????????????? @p*0???p@ ?? @p?? ??? ??0 ???? @p*?? ??? ??04Vx?*??? @? @p*???? ??? 0???? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 0 0 0 0 0 0 0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @ @ @ @ @ @ @ @ p p p p p p p p * * * * * * * * ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 0 0 0 0 0 0 0 4 4 4 4 4 4 4 4 V V V V V V V V x x x x x x x x ? ? ? ? ? ? ? ? * * * * * * * * ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @ @ @ @ @ @ @ @ ? ? ? ? ? ? ? ? @ @ @ @ @ @ @ @ p p p p p p p p * * * * * * * * ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0 0 0 0 0 0 0 0 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

I would be grateful for your kind feedback.

Thanks!

What’s your question?

How do I save the buf output in binary?

It looks like you’re doing it.

Well the output is stored as ascii values in the file oct6, and I have shown the output of this particular file in the first post.

I also printed the buf values using for loop and I can see as hex values in the output, but some how I am not able to configure out why it is storing values in ascii rather than binary…
please help!!!

Thanks!

That doesn’t look like ASCII to me. What do you mean ASCII? What do you think ASCII looks like?

Well, when I opened this file in a hex editor it shows all the values in hex…but my issue is to store it into binary?

I am almost using the same code of DES for writing into a file, but when I compile the DES it saves it into binary and this code does not saves into binary values…

How do I save the buf output in binary or hex in a text file?

Thanks!

I’m sorry, but I’m really not understanding what the issue is here.

When you open a file in a hex editor, it will typically display it as hex. Afterall, that’s what hex editors do.

Your best bet for assistance here is probably a good C or C++ text or Googling for information. Unfortunately, from where I stand, your code is doing exactly what you want it to do – you just haven’t realized it yet.