Okay I am making a program and I want the user to input some data that starts with zeros, this code here displays an example of what I am talking about:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
usingnamespace std;
int value;
int main()
{
cout << "Enter a hex value: 0x";
cin >> hex >> value;
system("cls");
cout << "Your value is 0x" << hex << value << endl;
system("pause");
}
But when I display it to the screen and I enter a value like 0x00000004 or what ever it displays as 0x4 it deletes the zeros. Any way to stop this?
I assume hex here is an int. As int is a simple number, it only preserves the value itself and not the form in which it was written. You could use strings here instead, and convert them to ints whenever you need to calculate stuff.
I tried using stringstreams and it didn't work. and I know that I can use strings but in the thing I am making I need to change the hex value. And the same thing happens if it is hex or not.