Wide character string class

Started by
5 comments, last by Kurioes 20 years, 11 months ago
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.
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>.
quote:Original post by Kurioes
Original post by civguy
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.

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]
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Would SC (in the Unicode case) be #defined as
#define SC(x) L##x
?

I like this #define and typedef idea.
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.



[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
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.
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com

This topic is closed to new replies.

Advertisement