Juce::String treat uint32 as a utf-32 wchar, but not a unsigned int

This problem can be reproduced in the newest version 3.2.0 with VS2013 community edition. 

The OS is 64bit Windows 7 with SP1.

The code:

juce::String str;
uint32 id = 1;
str << id;
std::cout << str;

The result:

str = '\x1'

There is a strange smile character in the console window. But what I expect is a number "1".

It makes me confused. I tried to debug the code and find that uint32 is typedef to juce_wchar.

Is it a bug?

How can I get a normal uint32 number with juce::String?

Please help me, thx.

This isn't a bug - there's a fundamental problem with older Visual Studio compilers where they couldn't distinguish between the types of an unsigned int and a wide char, so it was impossible to give String overloaded operators to handle the types differently.

I think Joshua has been tinkering around with this recently, as we may be able to change things so that it works as you'd expect if you're using an up-to-date C++ compiler, and we'll probably release some changes for that soon.

Thx for your reply.

I think it is more commonly use a uint32 as a number than a wide char, at least in my situation.

So is there a temperary solution to make it works as a number ?

I'm okay without utf-32 support.

Simply change JUCE_NATIVE_WCHAR_IS_UTF32 0 to 1 does't work.


Sure, of course we know that some people will find uint32 more useful, and others will find wide-chars more useful.

But as library writers we have to release code that suits everybody, and we can't make changes that would change the behaviour of people's existing code, so we can't just change this to work the way you'd like it to.

But this is easy for you to work around: just cast your uint32 to an int.

Fair enough.

This hack is good enough for me. Thank you.