-
DWORD to CString
I'm converting a DWORD which represents a CRC to a string.
This works fine but whenever the DWORD is preceded by a
zero, it's truncated and not included in the string.
Code:
_itoa(dwChecksum, buffer, 16);
Is there another way to do this without losing that first zero?
-
You could always convert it, then see how many characters there are.
Or, you could use a stringstream to do it for you:
Code:
#include <iostream>
#include <sstream>
#include <iomanip>
void somecode() {
ostringstream oss;
oss << setw(8) << setfill('0') << 6574;
string whatever = oss.str();
}
-
thx, i had the value in a CString so i just tested to make sure the
length was 8 and added a '0' otherwise
-
Or use the CString::Format function. I works like sprintf.