如果涉及不同的代码集,您将需要使用 您用于开发的框架提供的库 (例如MFC) ,Borland上的VCL)或者使用适合的Windows API函数 。 你的编译器可能已经实现了一些方便的方面,这些方便了一些 通过std :: [w] iostream转换,例如退房: std :: ios_base :: imbue(const std :: locale&))。 请注意一些库函数对于Windows上的COM / OLE期望BSTR 参数,或者返回BSTR,这是一种非标准的OLE数据类型 虽然我认为它被定义为WCHAR * 。这是一款完全不同的颜色,并且存在内存管理问题 这些是特定于操作系统的。如果这是你需要的,那就去一个 微软新闻组来处理Windows特定的C ++ 开发。 - Bob Hairgrove 否******** **@Home.com<OT-rant>WCHAR is a non-standard Windows type. Therefore, it is off-topic incomp.lang.c++ which concerns itself only with ANSI and ISO standardC++ language topics. Please read the FAQ for this newsgroup at: http://www.parashift.com/c++-faq-lite/</OT-rant>Nevertheless, you are stuck with a std::string and need to know whatto do with it. It depends on how the std::string''s character data isencoded, i.e. which locale or code page is used.Fr starters, I will assume you know that there are several differentUnicode encodings (http://www.unicode.org). WCHAR is defined as a"16-bit Unicode character" which is only one of them.For data which comes from Western European code set (i.e. ISO-8859-1or ISO-8859-15), the conversion is trivial since the MSB (mostsignificant byte) is always 0. You need to supply a buffer of WCHAR,which is large enough to contain all the character data plus oneterminating null WCHAR, and merely copy the characters from thestring. Don''t use memcpy or such, but use a loop and copy it characterby character into the buffer. If the buffer is allocated dynamically,be sure to release the memory by calling delete[] (if you used new[])when you are done, or else use a smart pointer which can handle arraydata (std::auto_ptr<> cannot ... there are such smart pointers in theBoost library, though: http:://www.boost.org ).Since your post seems to originate in France, be aware that the Eurocharacter "?" has a Unicode encoding of 0x20ac, therefore the MSB is*not* zero for this particular character. In Windows, it is defined as0x80 which is (AFAIK) a non-printable character in ISO-8859-1 codepage.If there is a different code set involved, you will need to use eitherthe libraries supplied by the framework you are using for development(e.g. MFC, VCL on Borland) or use the Windows API functions suitablefor this.Your compiler may have implemented locale facets which facilitate someconversions via std::[w]iostream, e.g. check out:std::ios_base::imbue(const std::locale &)).Note that some library functions for COM/OLE on Windows expect a BSTRargument, or return a BSTR, which is a non-standard OLE data typealthough I believe it is defined as WCHAR*. This is a horse of anentirely different color, and there are issues with memory managementwhich are OS-specific. If this is what you need, go to one of theMicrosoft newsgroups which deals with Windows-specific C++development.--Bob Hairgrove No**********@Home.com 这篇关于std :: string - > WCHAR *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 1403页,肝出来的.. 09-06 08:36