c/c++ 中文字符串转Unicode和UTF8
来源:互联网 发布:qq飞车绿光使者数据 编辑:程序博客网 时间:2024/06/06 00:14
1. 描述
在windows上做系统编程,少不了会遇到处理中文字符串的问题。而大多时候中文汉字都是以多字节编码的方式展现的。为了实现更好的兼容性或一些特殊的需求,(比如在网页上显示。)常需要将其转换成unicode或者utf8的格式。
2. 代码示例
2.1 中文字符串转Unicode
/*************************************************************************int CN2Unicode(char *input,wchar_t *output)*功能:中文字符转换为unicode字符*参数:input,包含中文的字符串,output,Unicode字符串**************************************************************************/int CN2Unicode(char *input,wchar_t *output){ int len = strlen(input); //wchar_t *out = (wchar_t *) malloc(len*sizeof(wchar_t)); len=MultiByteToWideChar(CP_ACP,0,input,-1,output,MAX_PATH); return 1;}
2.2 中文字符串转utf8
/*************************************************************************int CN2Utf8(char *input,char *output)*功能:中文字符串转换为utf8字符串*参数:input,包含中文的字符串,output,utf8字符串*************************************************************************/int CN2Utf8(char *input,char *output){ int len ; wchar_t *out = (wchar_t *) malloc(len*sizeof(wchar_t)); len = MultiByteToWideChar(CP_ACP,0,input,-1,out,strlen(input)+1); WideCharToMultiByte(CP_UTF8,0,out,wcslen(out),output,len,NULL,NULL); return 1;}
0 0
- c/c++ 中文字符串转Unicode和UTF8
- [C/C++]_[utf8字符串转换为unicode字符串]
- [C/C++]_[单个Unicode转UTF8]
- c#unicode转中文
- UTF8编码转Unicode编码(C语言)
- UTF8编码转Unicode编码(C语言)
- [C/C++]_[utf8和unicode的相互转换]
- [C语言]字符串处理 - ANSI - Unicode - UTF8 转换
- [C/C++]_[Unicode转Utf8,Ansi转Unicode,Ansi文件转Utf8文件]
- [C/C++]_[Unicode转Utf8,Ansi转Unicode,Ansi文件转Utf8文件]
- qt5 unicode 转中文 utf8
- objective-c unicode转中文
- objective-c Unicode转中文
- objective-c Unicode转中文
- objective-c Unicode转中文
- C语言实现Unicode和UTF8之间的转换
- Utf8和Unicode转换问题 C语言 千字文问题
- C++unicode中文显示
- LeetCode 22 - Generate Parentheses
- 2015年大一下第11周项目4-点、圆的关系(1)重载输入输出函数
- STL-set
- Kithings如何选择Wi-Fi物联网芯片(第一篇)
- HDOJ Flow Problem 3549(最大流)
- c/c++ 中文字符串转Unicode和UTF8
- sgu225:Little Knights(状压DP+打表)
- SpringMVC-15 异常处理
- STL-stack
- STL-queue
- Mybatis传多个参数(三种解决方案)
- 接单流程
- MappedByteBuffer
- EXCEL表的MFC导入