Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to use cout manipulator to set hex output with uppercase in C++

1 Answer

0 votes
#include <iostream>

using namespace std;

ostream &sethex(ostream &stream)
{
	stream.unsetf(ios::dec | ios::oct);
	stream.setf(ios::hex | ios::uppercase | ios::showbase);

	return stream;
}

ostream &noset(ostream &stream)
{
	stream.unsetf(ios::hex | ios::uppercase | ios::showbase);
	stream.setf(ios::dec);

	return stream;
}

int main()
{
	cout << sethex << 65 << endl;
	cout << noset << 65 << endl;

	return 0;
}


/*
run:

0X41
65

*/

 



answered Apr 9, 2018 by avibootz

Related questions

1 answer 167 views
1 answer 197 views
1 answer 297 views
1 answer 167 views
1 answer 139 views
1 answer 141 views
...