c++宽字符串、窄字符串 互转
来源:互联网 发布:穿越火线手游淘宝商城 编辑:程序博客网 时间:2024/04/30 15:39
Unicode字符集环境下亲测可用:
//------------------------------------------------------------------宽字符串转换到窄字符串char* pC = NULL; wchar_t wStr[20] = L"宽字符串"; int iLen = WideCharToMultiByte( CP_ACP,0,wStr,-1,NULL,0,NULL,NULL); if( iLen > 0 ){ pC = ( char* )HeapAlloc( GetProcessHeap() ,0 ,iLen ); if( !pC ) return; WideCharToMultiByte( CP_ACP ,0 ,wStr ,-1 ,pC ,iLen ,NULL ,NULL ); printf( "%s \n", pC ); HeapFree( GetProcessHeap() ,0 ,pC );}//------------------------------------------------------------------窄字符串转换到宽字符串char cStr[20] = "这是窄字符串"; wchar_t* pWideString = NULL; int iLenWide = MultiByteToWideChar( CP_ACP ,0 ,cStr ,-1 ,NULL ,0 ); if ( iLenWide > 0 ){ pWideString = ( wchar_t* )malloc( iLenWide * sizeof(wchar_t) ); if( !pWideString ) return 0; MultiByteToWideChar( CP_ACP ,0 ,cStr ,-1 ,pWideString ,iLenWide ); MessageBox( NULL, pWideString , 0 , 0 ); free( pWideString ); }
0 0
- c++宽字符串、窄字符串 互转
- C字符串
- C++--字符串
- C字符串
- [C#] 字符串
- c字符串
- C++--字符串
- C-字符串
- C-字符串
- C:字符串
- C字符串
- C 字符串
- C--字符串
- C 字符串
- C字符串
- 【c++】字符串
- C字符串
- 【C++】字符串
- 【值对象】--NSNull NULL nil
- 高性能libcurl配合epoll的curl_multi_socket_action方法使用
- 简单东西-jQuery过滤数值
- Java 线程
- logger(二):linux下syslog & syslog-ng 详解
- c++宽字符串、窄字符串 互转
- Ajax常见面试题
- ZXing生成条码二维码并输出到web页面的示例
- NSHashTable 和 NSMapTable的学习
- 多方位全面解析:如何正确地写好一个界面
- IOS上 关于状态栏的相关设置(UIStatusBar)
- 6.php职责链
- Android开发中集成protobuf协议
- CustomAnim自定义动画