如果我输入 -4094,我的输出将如下所示。
[Hexadecimal: fffff002]
我试图为我的十六进制输出保留前导零。前导零是指输出左侧的额外“f”字符。 我的结果应该如下。
[Hexadecimal: fffffffffffff002]
我怎样才能做到这一点?
这是我的代码。
#include <iostream> //Header needed for input/output operations
#include <iomanip> //Header needed for hexadecimal output
#include <sstream> //Header needed for stringstream type
using namespace std;
int main()
{
int num;
cout << "Please enter number to convert: ";
cin >> num;
stringstream ss;
ss << hex << (num);
string res(ss.str());
cout << " [Hexadecimal: " << res << "]\n\n";
return 0;
}