MeJ
MeJ

Reputation: 1108

Boost::format hex output

I'm using boost::format to create and format a string.

I would like to create following output:

Data: 0x64 - Name: 'xxx', Value: 10

I tried it with following line:

boost::format("Data:  %|02x|%1% - Name: '%2%', Value: %3%") % code % name % value);

but it doesn't work.

I know that the formation of the first parameter is wrong, but I am not able to fix it.

Is there a possibility to print the first parameter as hex?

Upvotes: 5

Views: 8740

Answers (1)

ForEveR
ForEveR

Reputation: 55887

Just use

boost::format("%1$#x")

this means - output first argument in hex form with numerical base.

More information here

Upvotes: 12

Related Questions