views:

101

answers:

3

Hi stackoverflow!

I am trying to insert the Unicode character U+2022 (bullet ) in my C++ application.

I can't figure out how to convert that U+2022 to a char/string for use in std::string constructor...

char bullet = char(0x2022);
mPassword.SetText( std::string(mText.length(), bullet) );

This one doesn't work. Hope you can help !!

Thanks
opatut

+3  A: 
Kirill V. Lyadvinsky
It should be noted that depending on your locale in Linux, std:string is technically treated as a series of UTF-8 code units, so it deals with unicode correctly. However, I have no idea how you'd set any of them individually if you wanted anything other than ASCII and wanted to set it in the code rather than reading in something that's already unicode (you'd probably have to figure out what each code unit was rather than setting a whole code point at once). However, on Windows, I think that you do indeed have to use std::wstring.
Jonathan M Davis
I still have a problem. I simply do not get the bullet point on my output. std::wcout outputs quotes (")
opatut
The problem is in the console. Check [this](http://stackoverflow.com/questions/2492077/output-unicode-strings-in-windows-console-app) question if you use Windows.
Kirill V. Lyadvinsky
+1  A: 

This seems like a duplicate of http://stackoverflow.com/questions/442735/how-can-i-embed-unicode-string-constants-in-a-source-file

I'd post this as a comment but I don't have enough repz yet; so my apologies for that..

PersonalHomePage
+1  A: 

use std::wstring which is that same as std::string but specialized on wchar_t

Steve Townsend