Problem with 0

Good day guys how can i display the 0 when i enter a number like 00005?
1
2
3
4
5
6
7
8
9
10
#include <iostream>

using namespace std;

int main()
{
int num;
cin>>num;//00005
cout<<num;//output is 5
}

i can do it with string and char but i want to do it in a integer data type
Integers store anstract number. As there is no difference between 5 and 00006 cars, you will get same value no matter how many leading zeroes you enter. Depending on your needs you will either have to store your number as string or use manipulators to widen your number.
As there is no difference between 5 and 00006 cars

LOL. Only for used cars, though.

1
2
3
4
5
6
7
8
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
  cout << setw( 5 ) << setfill( '0' ) << 5 << "\n";
}

The fill character is a permanent modification you make to a stream (so you only need to set it once).

The width is a temporary modification that only affects the next item being output (so you'll need to set it for each number you wish to output).

Hope this helps.
Topic archived. No new replies allowed.