質問

I'm trying to write the contents of a pointer to a stream in hex. I've tried setting the stream to use the hex format flag, but it doesn't seem to have an effect when using the write method. Below is my current code:

char* pointerToData;
size_t dataLength;
....
out.setf(std::ios::hex, std::ios::basefield);
out.setf(std::ios::showbase);
out.write(pointerToData, dataLength);
os.unsetf(std::ios::showbase);
役に立ちましたか?

解決

The hex flag affects how integer values are formatted. When you call write with a buffer it's not formatting anything. You need something roughly like this:

for (size_t ii = 0; ii < dataLength; ++ii) {
    out << int(pointerToData[ii]);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top