Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decimal value of: cout << dec << boost::this_thread::get_id()

Is it possible to cout thread::id in a decimal or octal format?

std::cout << std::showbase;
cout << dec(or oct) << boost::this_thread::get_id() 

I got always hex, for example 0xdf08.

like image 621
Ivan Kush Avatar asked Jun 17 '13 19:06

Ivan Kush


1 Answers

You should be able to specify what output format you want by using standard I/O manipulators:

#include <iomanip>

// ...

std::cout << std::oct << boost::this_thread::get_id() << std::endl;
//           ^^^^^^^^
//           Octal

std::cout << std::dec << boost::this_thread::get_id() << std::endl;
//           ^^^^^^^^
//           Decimal

std::cout << std::hex << boost::this_thread::get_id() << std::endl;
//           ^^^^^^^^
//           Hexadecimal

However, notice that a thread::id does not need to be a number. Also, it may be a number but may be printed to the standard output in a different way than just inserting that number into std::cout.

The C++11 Standard specification the overload of operator << accepting an std::thread::id (which I assume to behave similarly to Boost's correspondent overload for boost::thread::it), says:

[...] Inserts an unspecified text representation of id into out.

This means the representation may not be a number at all, in which case formatting manipulators such as std::hex,std::dec, or std::oct may not have any influence on it.

like image 144
Andy Prowl Avatar answered Nov 17 '22 04:11

Andy Prowl