[转载] c++中UTF-8到ANSI的转换
来源:互联网 发布:淘宝店铺装修的流程 编辑:程序博客网 时间:2024/06/02 05:56
目 前 许 多 数 据 库 中 数 据 的 存 储 编 码 是 Utf-8 格 式 的 , 而 我 们 在 编 程 时 默 认 使 用 的 是 ANSI 编 码 , 从 数 据 库 里 提 取 数 据 时 经 常 会 遇 到 乱 码 的 情 形 , 如 题 , 提 供 一 个 格 式 转 换 函 数 , 自 己 写 的 , 敬 请 各 位 达 人 批 评 指 正 。
原文地址:http://bbs.sciencenet.cn/thread-107913-1-1.html
//实现编码由utf-8到ANSI的转换char*Utf2ANSI(char*srcCode){ int srcCodeLen=0 ; srcCodeLen=MultiByteToWideChar(CP_UTF8,NULL,srcCode,strlen(srcCode),NULL,0); wchar_t*result_t=new wchar_t[srcCodeLen+1]; MultiByteToWideChar(CP_UTF8,NULL,srcCode,strlen(srcCode),result_t,srcCodeLen); //utf-8转换为Unicode result_t[srcCodeLen]='\0' ; srcCodeLen=WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),NULL,0,NULL,NULL); char*result=new char[srcCodeLen+1]; WideCharToMultiByte(CP_ACP,NULL,result_t,wcslen(result_t),result,srcCodeLen,NULL,NULL); //Unicode转换为ANSI result[srcCodeLen]='\0' ; delete result_t ; return result ;}
原文地址:http://bbs.sciencenet.cn/thread-107913-1-1.html
0 0
- [转载] c++中UTF-8到ANSI的转换
- unicode, ANSI, utf-8字符集之间的转换 C,C++
- ansi转换 utf-8 转
- Delphi中文本文件Utf-8和Ansi转换
- [转载]Unicode、ANSI、UTF-8、Unicode Big Endian的故事
- C++中,将.txt文件的编码由UTF-8转换为ANSI
- C++中,将.txt文件的编码由UTF-8转换为ANSI
- ANSI,UNICODE, UTF-8 字符串之间的相互转换
- ANSI,UNICODE, UTF-8 字符串之间的相互转换
- .java文件的ANSI编码转换为UTF-8编码
- unicode、utf-8、ansi的故事及其相互转换
- .java文件的ANSI编码转换为UTF-8编码
- ANSI、UNICODE、UTF-8 文件编码转换
- UTF-8与ANSI 编码转换
- ANSI UNICODE UTF-8转换源码
- ANSI与UTF-8编码转换
- ansi unicode utf-8相互转换
- Unicode和ansi及Utf-8转换
- 第三章 29题
- MVC 列表多条件动态查询分页
- 使用缓冲输入输出字节流拷贝图片
- PHPCMS v9 安全防范教程
- Swift学习之路一,常量&变量
- [转载] c++中UTF-8到ANSI的转换
- 标准Fibonacci序列(简单介绍)
- MyBatis+Spring
- 第一个Cygwin下的shell脚本问题
- 把一首MP3切成n份,每份是1m,然后再合并起来。
- 初识jQuery的ajax
- Leetcode_Number of 1 Bits
- C运算符优先级歌
- Linux安装JDK