1

I'm using a function that reads a spooled file and sets a buffer with the output. The function returns OK state and sets readBytes correctly. It also notifies that the reading operation has reached the end of the file.

char* splFileContent = new char[3000];
ULONG readBytes;
int z = cwbOBJ_ReadSplF(splFile, splFileContent, 500, &readBytes, 0);
//z value is REACHED END OF FILE or OK if read but didn't reach the end of the file.

The trouble comes when trying to convert the char buffer to string, I'm getting "4Ä" as string value...enter image description here

I convert the char buffer to string this way:

stringstream s;
s << splFileContent;
string bufferContent = s.str();

What I'm doing wrong?

1
  • You can convert to a string using string bufferContent(splFileContent, readBytes) ; Commented Aug 3, 2015 at 12:33

1 Answer 1

2

It looks like splFileContent is binary content and not printable characters.

The start of the file may contain a BOM of some sort, e.g. unicode indicator. If it is, you should read in the BOM first and then the rest of the file.

Note: unless the file read function here adds a NULL, be sure to append one as well.

Sign up to request clarification or add additional context in comments.

2 Comments

How can I convert binary chars to ascii? Thanks.
Generally you transform the byte wide binary to a hexadecimal string two bytes wide (each character would be in the range [0-9A-F]). You could use streams, sprintf functions etc. There are several popular techniques.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.