Jump to content
  • Advertisement
Sign in to follow this  
leidegren

C++ ANSI and Unicode tips&tricks

This topic is 3878 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm wondering what you guys know about ANSI and Unicode strings in C++ ... For the most part if you write a quoted string "Hello World" it's a standard ANSI string right? Yet MS has some notation L"Hello World" to make it wide or unicode, and there's also some type TCHAR which seem to depdning on project settings... and don't forget the TEXT("Hello World") macro as well... How much of this is C++ standard, and how much is MS specific, or is it all MS specific? Also, i thought this could be a nice thread to disscuss localization issues and ANSI/Unicode string handling... I've currently set up my game so that all strings are defined by the compiler, and use single-byte or multi-byte strings depending on project settings... Should i scrapp this and just go with standard UTF-8 encoding? I've come to realize that UTF-8 uses a varible byte length depending on what type of character there is, and that it maps the ANSI character space exactly...

Share this post


Link to post
Share on other sites
Advertisement
"this" is a narrow string.
L"this" is a wide string. This is standard C++, not Microsoft-specific.

Microsoft offers tchar.h, which contains the T() macro, which you can use to write code that can be narrow or wide depending on whether or not UNICODE is defined.

T("this") is "this" when UNICODE is not defined, and L"this" when it is.

The Win32 API generally uses T to indicate where a string can be either (at compile time) -- for example, LPTSTR, LPCSTR, LPWSTR. TCHAR is similarly char or wchar_t depending on whether UNICODE is defined or not.

Only L"" is standard C++, the rest is utility and helper stuff defined by Win32 API. Other APIs offer similar helper functionality, although I rarely find a need for it -- I generally simply only use Unicode nowadays, except when I have to deal with legacy APIs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!