2009-11-12 203 views

回答

1

我发现wcstombs的伟大工程,做这样的事情,

2

A TCHAR可能是一个普通的charwchar_t,具体取决于您的项目设置。如果是后者,则需要使用WideCharToMultiByte以及适当的代码页参数。

+0

这是后者 - “我使用unicode设置” – MSalters 2009-11-12 12:24:41

+0

原始文章中缺少此信息,在编辑之后添加。 – dirkgently 2009-11-12 12:26:31

2

不能转换的指针,你需要分配一个新的字符串,它是“字符”,而不是“wchar_t的”

的最优雅的方式做,这是与ATL转换宏,因为它会隐藏所有的分配,并呼吁在其他意见中提到的功能

例如

#include <atlbase.h> 
#include <atlconv.h> 

void YourFunction() 
{ 
    TCHAR wszHelloTchar = _T("Hello!\n"); 

    USES_CONVERSION; // a macro required once before using T2A() and other ATL macros 

    // printf require a char* 
    // T2A converts (if necessary) the TCHAR string to char 
    printf(T2A(wszHelloTchar)); 
} 
相关问题