Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Kurioes

Wide character string class

This topic is 5701 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

Hi, I want to make sure my creations support unicode... imagine it''d sell one day and it doesn''t support wide character strings; that would suck. I want to use a std::string class supporting Wide character strings. I got as far as going to www.sgi.com and finding stuff about character_traits and all but all this template stuff confuces me. My question is: is there a wchar_t string type (basic_string)? Second, I''d like any pointers anyone can give me about integrating wide char/multi language support with windows apps. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
quote:
Originally in here.
The basic_string class is parameterized by character type, and by that type''s Character Traits. Most of the time, however, there is no need to use the basic_string template directly. The types string and wstring are typedefs for, respectively, basic_string<char> and basic_string<wchar_t>.

Share this post


Link to post
Share on other sites
quote:
Original post by Kurioes
[quote]Original post by civguy
[quote]Originally in here.
The basic_string class is parameterized by character type, and by that type''s Character Traits. Most of the time, however, there is no need to use the basic_string template directly. The types string and wstring are typedefs for, respectively, basic_string and basic_string.


I read that part... and missed it

Thank you.

I would still appreciate hints/pointers on wide string issues however.

Share this post


Link to post
Share on other sites
Under Windows you can compile for MBCS or for UNICODE, and a macro TCHAR will be defined as char or wchar_t respectively.

I typedef std::basic_string<TCHAR> tstring; (along with a huge pile of other typedefs, #defines, and overloads) to have a consistent (portable) syntax for compile the code with both unicode and a multi-byte strings.

The most annoying part, is the unicode string literals needs to be prefixed by L. So you need a marco to decide if you need the prefix or not, I use SC for lack of a better choice.

tchar str[] = SC("This will work with both MBCS and UNICODE");
tcout << str << endl;
size_t n = tcslen(str); //calls strlen for MBCS, wcslen for UNICODE

It's important to remember that the character size can be either 1 or 2.

[edited by - Magmai Kai Holmlor on May 5, 2003 1:05:14 AM]

Share this post


Link to post
Share on other sites
Would SC (in the Unicode case) be #defined as
#define SC(x) L##x
?

I like this #define and typedef idea.

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor
...

The most annoying part, is the unicode string literals needs to be prefixed by L. So you need a marco to decide if you need the prefix or not, I use SC for lack of a better choice.

...



Maybe I''m missing something but why not just use the _T or TEXT macros provided in Windows SDK tchar.h header file?

TCHAR* p = TEXT("My text");

Under MBCS it will compile as:

char* p = "My text";

and under UNICODE it will compile as:

wchar_t* p = L"My text";


Hehe.



Share this post


Link to post
Share on other sites
quote:
Original post by Kurioes
Would SC (in the Unicode case) be #defined as
#define SC(x) L##x
?

I like this #define and typedef idea.


Just use the ones provided in the tchar.h header.

Use _T or TEXT, they both do the same thing.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!