|
From: lost_in_space on 17 May 2008 21:50 Hi, all - How do I use the wchar_t based basic_string derived 'string' class? I though all I had to do was #define _UNICODE and include <string>, and the class implementation would be typedef'd to the wchar_t based version. I have selected 'Use UNICODE character set' in my project settings, but it seems that the 'string' class is still based on 'char', and not 'wchar_t'. Is there something I'm missing?
From: Carl Daniel [VC++ MVP] on 17 May 2008 22:25 lost_in_space wrote: > Hi, all - > > How do I use the wchar_t based basic_string derived 'string' class? I > though all I had to do was #define _UNICODE and include <string>, > and the class implementation would be typedef'd to the wchar_t based > version. I have selected 'Use UNICODE character set' in my project > settings, but it seems that the 'string' class is still based on > 'char', and not 'wchar_t'. > Is there something I'm missing? Yes - you're missing the fact that it doesn't work that way. Regardless of UNICODE or _UNICODE, std :: string is always a narrow-charater string and std :: wstring is always a wide character string, as specified in the C++ standard (which knows nothing about those macro definitions). Some people prefer to use something like: #include <string> typedef std :: basic_string<TCHAR> tstring; ....while others think that's completely evil. Personally, I think you need to consider how your program uses the strings and make the appropriate choice. Do you always want wide-strings? If so, just use std :: wstring. -cd
From: Tim Roberts on 18 May 2008 00:27 "lost_in_space" <a(a)b.com> wrote: > >How do I use the wchar_t based basic_string derived 'string' class? I >though all I had to do was #define _UNICODE and include <string>, and the >class implementation would be typedef'd to the wchar_t based version. I have >selected 'Use UNICODE character set' in my project settings, but it seems >that the 'string' class is still based on 'char', and not 'wchar_t'. > >Is there something I'm missing? Yes. UNICODE and _UNICODE are strictly Microsoft inventions. The std::string type is a C++ standard thing. There is a std::wstring type that implements a string of wchar_t's. You can certainly implement: #ifdef UNICODE #define tstring std::wstring #else #define tstring std::string #endif and now "tstring" will match the current definition of UNICODE. -- Tim Roberts, timr(a)probo.com Providenza & Boekelheide, Inc.
From: lost_in_space on 18 May 2008 05:08 Thanks, Tim. That's what I'm after - I'm trying to implement a little library that will work with either single or double-byte characters depending on the definition of UNICODE. Pretty basic, I know, but it's something I'd never done before. Thanks again. "Tim Roberts" <timr(a)probo.com> wrote in message news:3sbv24lr8jvii3e6glto293rt5m3cp8dfr(a)4ax.com... > "lost_in_space" <a(a)b.com> wrote: >> >>How do I use the wchar_t based basic_string derived 'string' class? I >>though all I had to do was #define _UNICODE and include <string>, and the >>class implementation would be typedef'd to the wchar_t based version. I >>have >>selected 'Use UNICODE character set' in my project settings, but it seems >>that the 'string' class is still based on 'char', and not 'wchar_t'. >> >>Is there something I'm missing? > > Yes. UNICODE and _UNICODE are strictly Microsoft inventions. The > std::string type is a C++ standard thing. > > There is a std::wstring type that implements a string of wchar_t's. You > can certainly implement: > > #ifdef UNICODE > #define tstring std::wstring > #else > #define tstring std::string > #endif > > and now "tstring" will match the current definition of UNICODE. > -- > Tim Roberts, timr(a)probo.com > Providenza & Boekelheide, Inc.
From: lost_in_space on 18 May 2008 05:09 Thanks, Carl. "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam(a)mvps.org.nospam> wrote in message news:uwoN$5IuIHA.552(a)TK2MSFTNGP06.phx.gbl... > lost_in_space wrote: >> Hi, all - >> >> How do I use the wchar_t based basic_string derived 'string' class? I >> though all I had to do was #define _UNICODE and include <string>, >> and the class implementation would be typedef'd to the wchar_t based >> version. I have selected 'Use UNICODE character set' in my project >> settings, but it seems that the 'string' class is still based on >> 'char', and not 'wchar_t'. >> Is there something I'm missing? > > Yes - you're missing the fact that it doesn't work that way. > > Regardless of UNICODE or _UNICODE, std :: string is always a > narrow-charater string and std :: wstring is always a wide character > string, as specified in the C++ standard (which knows nothing about those > macro definitions). > > Some people prefer to use something like: > > #include <string> > > typedef std :: basic_string<TCHAR> tstring; > > ...while others think that's completely evil. Personally, I think you > need to consider how your program uses the strings and make the > appropriate choice. Do you always want wide-strings? If so, just use std > :: wstring. > > -cd > >
|
Next
|
Last
Pages: 1 2 3 Prev: oldnames.lib in VS8 Next: Run-time error when Optimization turned on ? |