How can I print the value of std :: atomic <unsigned int>

I am using std::atomic<unsigned int> in my program. How to print its value using printf ? Because it does not work if I just use %u . I know I can use cout , but my program is dotted with printf calls, and I don't want to replace them. I used to use unsigned int instead of std::atomic<unsigned int> , so I just used %u , and so printing worked fine.

+6
source share
1 answer
 template<typename BaseType> struct atomic { operator BaseType () const volatile; } 

Use type casting to pull out the base value.

 printf("%u", unsigned(atomic_uint)); 
+13
source

Source: https://habr.com/ru/post/891446/


All Articles