how to format hex numbers using stringstream

setw is going to set the width of the entire formatted output, including the displayed base, which is why you’re not seeing the leading 0. Also, there’s no way to make the base be displayed in lowercase if you use std::showbase along with std::uppercase. The solution is to insert the base manually, and then apply the remaining manipulators.

ss << "0x" << std::uppercase << std::setfill('0') << std::setw(4) << std::hex << id;

This outputs 0x0467

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)