As I understand it, Microsoft's TCHAR type and _T() macro can morph
between char and wchar_t depending on whether UNICODE is defined.
With STL it appears you'd have to choose std::cout or std::wcout, but
there's no std::tcout. Same issue for the rest of the standard library.
Is there any way to switch the whole library between ANSI and Wide, or a
better way of doing it all together?
--
Gerry Hickman (London UK)
Jerry:
Just set it up yourself with typedef's and #define's. Do it in a header
that you can include it in all your projects.
David Wilkinson
--
David Wilkinson
Visual C++ MVP
Hope this helps. Please feel free to post back if you have any other
questions or concerns.
Have a nice day!
Best regards,
Charles Wang
Microsoft Online Community Support
=====================================================
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications
If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
======================================================
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
Best regards,
Charles Wang
Microsoft Online Community Support
======================================================
I understand the simple case of switching cout and wcout, but I was
really asking about the whole STL library? I'm guessing it would be a
big job to apply this technique to all of it?
Practically all of STL uses template argument deduction to use the right
character type automatically. Only streams and strings need to be specified
in most cases.
p.s. std::wcout cannot display non-ANSI Unicode characters on console.
"Gerry Hickman" <gerry...@newsgroup.nospam> ???
news:eYrjLyzv...@TK2MSFTNGP03.phx.gbl ???...
For your questions, I agree with Ben. In Microsoft STL, only streams and
strings need to be specified in most cases.
For example:
#ifdef _UNICODE
#define tstring wstring
#else
#define tstring string
#endif
Unfortunately there is no way to switch the whole library between ANSI and
Wide, however could you please let me know why you would like to switch the
whole library? In most cases, we just use very few of the library.
Appreicate your understanding that this is by design. If you have any other
questions or concerns, please feel free to let us know.
I have enough information now. I need to decide how to implement this in
future projects.
I think that you may collect and define those functions or modifiers by
using macros in one or several header files for your future use.
Please feel free to let me know if you need further assistance on this
issue. Have a nice day!
> Don't trust the Unicode support of STL until VS2005. It doesn't handle
> Unicode characters with codepoint>128 correctly.
>
> p.s. std::wcout cannot display non-ANSI Unicode characters on console.
I'm using VS2005 and associated PSDK libraries. Does the second part
still affect me?
I found a nice article on MSDN that covers most of what we've been
talking about.
http://msdn.microsoft.com/msdnmag/issues/04/08/CQA/
Apologies if I've already posted this link.
After looking at this in more detail, it appears there's more to it. I
have a project that demonstrates all the STL classes. When I started
trying to convert it, I found the task is not straightforward; the sheer
number of instances of cout, string, ofstream, then templates and
typedefs in header files adds up to a LOT of changes. Then I also
noticed this article
http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp
Most of it is over my head, but it raises other issues such as
unexpected conversions.
Thing is, I don't really need UNICODE for internationalization purposes,
my real concern is that I want all my "string" data to be compatible
with Microsoft WinAPI and COM, and I'm guessing that means I should run
with UNICODE. Not an issue with the WinAPI types, but seems a bit of a
headache with STL:(
> Hi Charles,
>
> I found a nice article on MSDN that covers most of what we've been
> talking about.
>
> http://msdn.microsoft.com/msdnmag/issues/04/08/CQA/
>
> Apologies if I've already posted this link.
>
> Charles Wang[MSFT] wrote:
>> Hi Gerry,
>> Thanks for your response.
>>
>> I think that you may collect and define those functions or modifiers
>> by using macros in one or several header files for your future use.
>>
>> Please feel free to let me know if you need further assistance on this
>> issue. Have a nice day!
>>
>> Best regards,
>> Charles Wang
>> Microsoft Online Community Support
--
Gerry Hickman (London UK)
Gerry:
What do you think is the problem exactly?
As to the #define's and typedef's for the C++ Standard Library, I just
have a header file that is used in each of my projects, and whenever I
need anything that isn't there I just add it.
But for me it's 99% tstring and tstringstream. I write my data files in
UTF-8, so I don't need wofstream. In Windows GUI programs I don't use
cout, and most of my console programs are cross-platform so I usually
just use 8-bit strings.
People say that std::string and std::wstring are not Unicode aware. This
is true, but neither are CStringA and CStringW for the most part.
> What do you think is the problem exactly?
Trying to come up with something that's write once, run many.
> As to the #define's and typedef's for the C++ Standard Library, I just
> have a header file that is used in each of my projects, and whenever I
> need anything that isn't there I just add it.
OK.
> But for me it's 99% tstring and tstringstream. I write my data files in
> UTF-8, so I don't need wofstream. In Windows GUI programs I don't use
> cout, and most of my console programs are cross-platform so I usually
> just use 8-bit strings.
I also want some of it to be cross-platform, or at least Windows/Linux.
Are you saying UNICODE is not the best option for cross-platform?
> People say that std::string and std::wstring are not Unicode aware. This
> is true, but neither are CStringA and CStringW for the most part.
Hmmm, well in earlier days I just used ANSI; the main reason I started
trying to get everything to work under UNICODE compile was to do with
Microsoft's COM e.g. DirectShow, WMI, MSI, ADSI, WUA.
For your concerns, "Most of it is over my head, but it raises other issues
such as unexpected conversions.", could you please take a sample for
instance?
Best regards,
Charles Wang
Microsoft Online Community Support
Best regards,
Charles Wang
Microsoft Online Community Support
======================================================
> Since your project demostrates all the STL classes, I am afraid that there
> might have a definite work volume. The work may need a few hours, however I
> think that it worth your try.
Yes, I think it will be a bigger job than I expected.
> For your concerns, "Most of it is over my head, but it raises other issues
> such as unexpected conversions.", could you please take a sample for
> instance?
What I mean is his BLOG post covers some complex issues, please see:
http://www.codeproject.com/vcpp/stl/upgradingstlappstounicode.asp
e.g. the code below and also the issue of byte conversions.
#include <locale>
// nb: MSVC6+Stlport can't handle "std::"
// appearing in the NullCodecvtBase typedef.
using std::codecvt ;
typedef codecvt < wchar_t , char , mbstate_t > NullCodecvtBase ;
class NullCodecvt
: public NullCodecvtBase
{
public:
typedef wchar_t _E ;
typedef char _To ;
typedef mbstate_t _St ;
explicit NullCodecvt( size_t _R=0 ) : NullCodecvtBase(_R) { }
protected:
virtual result do_in( _St& _State ,
const _To* _F1 , const _To* _L1 , const _To*& _Mid1 ,
_E* F2 , _E* _L2 , _E*& _Mid2
) const
{
return noconv ;
}
virtual result do_out( _St& _State ,
const _E* _F1 , const _E* _L1 , const _E*& _Mid1 ,
_To* F2, _E* _L2 , _To*& _Mid2
) const
{
return noconv ;
}
virtual result do_unshift( _St& _State ,
_To* _F2 , _To* _L2 , _To*& _Mid2 ) const
{
return noconv ;
}
virtual int do_length( _St& _State , const _To* _F1 ,
const _To* _L1 , size_t _N2 ) const _THROW0()
{
return (_N2 < (size_t)(_L1 - _F1)) ? _N2 : _L1 - _F1 ;
}
virtual bool do_always_noconv() const _THROW0()
{
return true ;
}
virtual int do_max_length() const _THROW0()
{
return 2 ;
}
virtual int do_encoding() const _THROW0()
{
return 2 ;
}
} ;
I looked through the article and understahd that there indeed might be many
works to do, however since the STL library itself has not provided a set of
neat definitions for swtiching UNICODE and non-UNICODE now, you may have to
implement it by yourself.
I also appreciate that if you could give Microsoft suggestions via the
following link:
https://connect.microsoft.com/VisualStudio/Feedback
Your suggestions will be routed to Microsoft product team and hope that the
product team can do some efforts to improve this feature in the future
release of Visual C++.
If you have any other questions or concerns, please feel free to let us
know.
Best regards,