converting to hex error

Hi I was trying to build a hex string from three integer values (r,g,b) but sometimes the output is slightly wrong.

when this code is supposed to print FFBF00 it prints FFBF0 (the last hex is displayed as one zero)


here's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <iomanip>

int main()
{
    using namespace std;


int r = 0xFF;
int g = 0xBF;
int b = 0x00;
  
    cout << uppercase<< hex << setw(2) << r  << g << b << endl;

    return 0;
}


does anyone know how to fix it?
setw only affects the next output operation of r .
Last edited on
@Peter87

Thanks, that was it.
Topic archived. No new replies allowed.