|
I need to read 512 bytes from a file and convert into a string. But first few bytes (10-15) are 0x0 and when I pass this buffer to string, I am getting empty string.
Buffer is having correct 512 bytes.
CStringA szMailContent(buffer);
Please help.
|
|
|
|
|
john5632 wrote: first few bytes (10-15) are 0x0
john5632 wrote: Buffer is having correct 512 bytes.
Both of these statements cannot be true. Either the buffer contains 512 characters or it contains something else, which may include some characters. Try showing how you read the buffer and what it contains when the read completes.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
john5632 wrote: But first few bytes (10-15) are 0x0
I think that is the key to your problem. The string of characters that will be placed into the szMailContent instance will consist of all characters in your buffer up until the first 0x0 is encountered. If you need your instance to be able to contain 0x0 characters, you will need to use some other class for that.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Something like:
BYTE buffer[512];
CFile file;
file.Read(buffer, sizeof(buffer));
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
You can make sure like this:
CFile file;
Char tempBuf[512];
file.Read(tempBuffer, 512);
|
|
|
|
|
manem21k wrote:
You can make sure like this: CFile
file; Char tempBuf[512]; file.Read(tempBuffer, 512);
Actually this will not work.
Char tempBuf[512]; <== wont compile there'e no Char data type
char tempBuf[512]; <== will compile
file.Read(tempBuffer, 512); <== wont compile, tempBuffer isn't declared
file.Read(tempBuf, 512); <== will compile
In other words see David's reply.
|
|
|
|
|
Thanks for correcting the typos. Yeah I have't run this program but just sure the code will resolve the problem.
|
|
|
|
|
Why do you want to initialize a CString with binary data?
Veni, vidi, vici.
|
|
|
|