以文本方式查看主题

-  法搜论坛  (http://www.fsou.com/forum/index.asp)
--  病毒黑客  (http://www.fsou.com/forum/list.asp?boardid=13)
----  unicode/ascii/char/w_char/wchar/w_char_t转换两个函数  (http://www.fsou.com/forum/dispbbs.asp?boardid=13&id=4346)

--  作者:helpuser
--  发布时间:2010-1-9 11:45:00

--  unicode/ascii/char/w_char/wchar/w_char_t转换两个函数
.如果是控制台或者标准c程序,那么如下函数:

mbstowcs

wcstombs

例子(参照msdn):

#include <stdlib.h>
#include <stdio.h>

int main( void )
{
    int i;
    char    *pmbnull = NULL;
    char    *pmbhello = (char *)malloc( MB_CUR_MAX );
    wchar_t *pwchello = L"Hi";
    wchar_t *pwc      = (wchar_t *)malloc( sizeof( wchar_t ));

    printf( "Convert to multibyte string:\\n" );
    i = wcstombs( pmbhello, pwchello, MB_CUR_MAX );
    printf( " Characters converted: %u\\n", i );
    printf( " Hex value of first" );
    printf( " multibyte character: %#.4x\\n\\n", pmbhello[0] );

    printf( "Convert back to wide-character string:\\n" );
    i = mbstowcs( pwc, pmbhello, MB_CUR_MAX );
    printf( " Characters converted: %u\\n", i );
    printf( " Hex value of first" );
    printf( " wide character: %#.4x\\n\\n", pwc[0] );
}

2.mfc(当然也能用上面的控制台)

MultiByteToWideChar

WideCharToMultiByte

相关用法参考msdn。

另外,string/BSTR/CString/char之间转换请参考:

http://www.codeproject.com/KB/string/bstrsproject1.aspx




Copyright ©2002 - 2005 Fsou.Com
执行时间:46.87500毫秒。查询数据库6次。
当前模板样式:[默认模板]