ANSI转UTF-8
来源:互联网 发布:mac系统最大化快捷键 编辑:程序博客网 时间:2024/05/29 17:31
说明:
记事本txt有四种编码方式,分别为:UTF-8、ANSI、Unicode和Unicode big endian,当进行写操作,创建的txt编码格式,与写入汉字的编码方式相同;如果写入的汉字是不同的编码方式,此时创建的txt中,会出现乱码,所以需要把汉字转化为同一编码方式。
本文主要介绍:把汉字编码方式,由ANSI方式转化为UTF-8方式:
一、ANSI转化为UTF-8程序:
CString ToUTF8(const wchar_t* buffer, int len) //返回类型为CString
{
int size = ::WideCharToMultiByte(CP_UTF8, 0, buffer, len, NULL, 0, NULL,
NULL);
if (size == 0)
return "";
std::string newbuffer;
newbuffer.resize(size);
::WideCharToMultiByte(CP_UTF8, 0, buffer, len,
const_cast<char*>(newbuffer.c_str()), size, NULL, NULL);
//如需返回string类型,直接 return newbuffer
TCHAR outstr[64]; //string 转化为CString返回
CString strTemp;
memset(outstr, '\0', sizeof(outstr));
memcpy(outstr,newbuffer.c_str(),newbuffer.size());
strTemp.Format("%s",outstr);
return strTemp;
}
二、函数调用形式
wstring text = L"汉字";
CString strTemp = ToUTF8(text.c_str(),text.size());
- UTF-8转ANSI
- ANSI转UTF-8
- ANSI转UTF-8
- ansi转换 utf-8 转
- UTF-8转ANSI的方法
- unicode、utf-8、ansi
- unicode、utf-8、ansi
- utf-8和ANSI
- ANSI UNICODE UTF-8
- [转]字符编码,ansi, unicode,utf-8, utf-16
- convert utf-8 to ansi
- ANSI UNIcode UNIcodebig UTF-8
- UTF-8转化ANSI编码
- ANSI,UNICODE,UTF-8,GB2312,GBK)编码问题(转)
- unicode,ansi,utf-8,unicode,big5有什么区别【转】
- unicode 和 utf-8 utf-16 utf-32 ASCII ANSI
- 字符编码 Unicode UTF-8 UTF-16 UTF-32 ANSI
- window下ANSI转UTF-8,UTF-8转Unicode的实现
- mysql安装
- 关于Android国际化的使用资源指定
- String to Integer (atoi)---题解
- opencv3.0中的无缝克隆图像——seamless_cloning(Poisson Image Editing)
- 捕获异常消息Ctrl+C
- ANSI转UTF-8
- c# winform 添加dataGridView数据源
- 【技术解密】SequoiaDB复制组选举原理说明
- 用两个stack实现queue
- B
- 做Java编程开发需要具备哪些软实力
- HTTP数据抓包(Fiddler2) V2.2.0 绿色中文版 和 教程网址:fiddler2抓包工具使用图文教程
- 杂记数据库
- 如何通过思维导图进行计划安排的6种模板鉴赏