stream manipulators help

I am suppose to create program that displays decimals in hex,dec and oct form using stream manipulators . i think i got right (can't check since my visual studios is not working

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
#include <conio.h>
#include <iomanip>
using std::dec;
using std::hex;
using std::oct;
int main()
{
	int number = 1;

	while (number <= 256)
	{
		std::cout << std::dec << number << "\t";
		std::cout << std::hex << number << "\t";
		std::cout << std::oct << number << "\n";

		number++;
	}


	_getch();
}
You could turn your while loop into a for loop to shorten the code and improve clarity.
Also, you don't need to write std:: in front of dec/hex/oct as you've brought them into scope with your using declarations.
Use std::showbase to make output more obvious.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>
using std::dec; using std::hex; using std::oct;
using std::showbase;
using std::cout;

int main()
{
    cout << showbase;
    for( int number = 1; number <= 256; number++ ) {
        cout << dec << number << "\t";
        cout << hex << number << "\t";
        cout << oct << number << "\n";
    }
}


1	0x1	01
2	0x2	02
3	0x3	03
4	0x4	04
5	0x5	05
6	0x6	06
7	0x7	07
8	0x8	010
9	0x9	011
10	0xa	012
...
Topic archived. No new replies allowed.