ASCII编码和UNICODE编码转换
来源:互联网 发布:java中final修饰的类 编辑:程序博客网 时间:2024/05/18 02:15
#include <stdio.h>#include <windows.h>#include <vector>#include <iostream>#include <string>using namespace std;//string转wstringinline void Ascii2WideString( const std::string& src, std::wstring& dest );//wstring转stringinline void WideString2Ascii(const std::wstring& dest,std::string& src);//TCHAR*转char*inline char* UnicodeToAnsi( const TCHAR* src,char* dest );//char*转TCHAR*inline TCHAR* AnsiToUnicode( const char* src,TCHAR* dest );int main (void){////char转wchar_t//char buffer[32]={"hello"};//TCHAR wBuf[64] = {0};//int len=sizeof(buffer);//int wlen=sizeof(wBuf);//MultiByteToWideChar(CP_ACP, 0, (const char*)buffer, len, wBuf, wlen);////wchar_t转char//TCHAR str1[32]={TEXT("world")};//char str2[64]={0};//int len1=sizeof(str1);//int len2=sizeof(str2);//WideCharToMultiByte(CP_ACP,0,(const TCHAR*)str1,len2,str2,len1,NULL,NULL);string str3="hello";wstring str4;Ascii2WideString(str3,str4);wstring str5=TEXT("hello world");string str6;WideString2Ascii(str5,str6);TCHAR str1[32]={TEXT("world")};char str2[64]={0};UnicodeToAnsi(str1,str2);char buffer[32]={"hello"};TCHAR wBuf[64] = {0};AnsiToUnicode(buffer,wBuf);return 0;}//string转wstringvoid Ascii2WideString(const std::string& src, std::wstring& dest){int nLength = MultiByteToWideChar( CP_ACP, 0, src.c_str(), -1, NULL, NULL );dest.resize(nLength);LPWSTR lpwszStr = new wchar_t[nLength];MultiByteToWideChar( CP_ACP, 0, src.c_str(), -1, lpwszStr, nLength );dest = lpwszStr;delete [] lpwszStr;return;}//wstring转stringvoid WideString2Ascii(const std::wstring& src,std::string& dest){int nLength = WideCharToMultiByte( CP_ACP, 0, src.c_str(), -1, NULL, NULL,NULL,NULL );dest.resize(nLength);char* lpwszStr = new char[nLength];WideCharToMultiByte( CP_ACP, 0, src.c_str(), -1, lpwszStr, nLength ,NULL,NULL);dest = lpwszStr;delete [] lpwszStr;return;}//将wchar_t*转char*char* UnicodeToAnsi(const wchar_t* src,char *dest){int nLen = WideCharToMultiByte( CP_ACP, 0, src, -1, NULL, 0, NULL, NULL );if (nLen == 0)return NULL;//char* pResult = new char[nLen];WideCharToMultiByte( CP_ACP, 0, src, -1, dest, nLen, NULL, NULL );return dest;}//char*转wchar*TCHAR* AnsiToUnicode(const char* src,TCHAR* dest){int nLen = MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, src, -1, NULL, 0 );if (nLen == 0)return NULL;//wchar_t* pResult = new wchar_t[nLen];MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, src, -1, dest, nLen );return dest;}
0 0
- ASCII编码和UNICODE编码转换
- Unicode ASCII 编码转换
- vbs实现unicode和ascii编码转换
- 编码转换(ASCII和Unicode、Unicode和中文相互转换)
- ASCII编码 和 UNICODE编码
- ASCII编码和Unicode编码
- ASCII和Unicode编码
- ASCII和Unicode编码详解
- ASCII和unicode编码区别
- ASCII编码和UNICODE、utf-8编码
- 中文转换Ascii和Unicode编码小工具-代码
- UFT-ASCII-GB2312-Unicode编码转换
- ASCII编码与Unicode编码
- ASCII编码与Unicode编码
- ASCII编码与Unicode编码
- ASCII,UniCode&UTF8编码
- Unicode Ascii编码问题
- AscII与Unicode编码
- org.mockito.exceptions.misusing.UnfinishedStubbingException
- ListCollectionView.Refresh issue
- 【keil配置,备查】STM32开发环境(工具)之Keil MDK 介绍
- Python中用eval将字符串转换为字典时候出错:NameError: name ‘null’ is not defined的解决方法
- IOS常用第三方框架 --- MBProgressHUD 提示效果
- ASCII编码和UNICODE编码转换
- Java开发环境搭建(一环境变量)
- Runtime之对象、类(类对象)、元类
- 电子商务文件存储及读取服务的设计和开发思路(JMagick用于生成高清的缩略图)
- Spring 3 REST hello world example
- OpenCV学习入门(三):kmeans原理及代码
- jQuery的deferred对象详解
- 测试人员都应该是好的产品人员
- Javascript中关于类型转换的一些问题