IO Manipulator: Partial 'uppercase'?

M

Marcus Kwok

When outputting an integer as hexadecimal, is it possible to set the
stream so that the basefield is lowercase, but the values are uppercase?
For example:


#include <iostream>

int main()
{
using std::cout;
using std::hex;
using std::showbase;
using std::uppercase;

int i = 42;
cout << i << '\n';
cout << hex << showbase << i << '\n';
cout << uppercase << i << '\n';
}


The output is:
42
0x2a
0X2A


However, I would like to have the output format be like:
0x2A
 
V

Victor Bazarov

Marcus said:
When outputting an integer as hexadecimal, is it possible to set the
stream so that the basefield is lowercase, but the values are
uppercase? For example:


#include <iostream>

int main()
{
using std::cout;
using std::hex;
using std::showbase;
using std::uppercase;

int i = 42;
cout << i << '\n';
cout << hex << showbase << i << '\n';
cout << uppercase << i << '\n';
}


The output is:
42
0x2a
0X2A


However, I would like to have the output format be like:
0x2A

Remove showbase and output "0x" yourself.

V
 
M

Marcus Kwok

Victor Bazarov said:
Marcus said:
When outputting an integer as hexadecimal, is it possible to set the
stream so that the basefield is lowercase, but the values are
uppercase? For example:
[snip]

However, I would like to have the output format be like:
0x2A

Remove showbase and output "0x" yourself.

OK, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top