C++中,将.txt文件的编码由UTF-8转换为ANSI
来源:互联网 发布:瓷砖铺设软件 编辑:程序博客网 时间:2024/05/17 03:08
1,将UTF-8转换为
int Utf8ToAnsi(const char *pstrUTF8, char *pstrAnsi)
{
int i = 0;
int j = 0;
char strUnicode[200] = {0};
i = MultiByteToWideChar(CP_UTF8, 0, pstrUTF8, -1, NULL, 0);
memset(strUnicode, 0, i);
MultiByteToWideChar(CP_UTF8, 0, pstrUTF8, -1, strUnicode, i);
j = WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, NULL, 0, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, strUnicode, -1, pstrAnsi, j, NULL, NULL);
return 0;
}
2,其他的编码转换
qp::StringW Global::AnsiToUnicode(const char* buf)
{
int len = ::MultiByteToWideChar(CP_ACP, 0, buf, -1, NULL, 0);
if (len == 0) return L"";
std::vector<wchar_t> unicode(len);
::MultiByteToWideChar(CP_ACP, 0, buf, -1, &unicode[0], len);
return &unicode[0];
}
qp::StringA Global::UnicodeToAnsi(const wchar_t* buf)
{
int len = ::WideCharToMultiByte(CP_ACP, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return "";
std::vector<char> utf8(len);
::WideCharToMultiByte(CP_ACP, 0, buf, -1, &utf8[0], len, NULL, NULL);
return &utf8[0];
}
qp::StringW Global::Utf8ToUnicode(const char* buf)
{
int len = ::MultiByteToWideChar(CP_UTF8, 0, buf, -1, NULL, 0);
if (len == 0) return L"";
std::vector<wchar_t> unicode(len);
::MultiByteToWideChar(CP_UTF8, 0, buf, -1, &unicode[0], len);
return &unicode[0];
}
qp::StringA Global::UnicodeToUtf8(const wchar_t* buf)
{
int len = ::WideCharToMultiByte(CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL);
if (len == 0) return "";
std::vector<char> utf8(len);
::WideCharToMultiByte(CP_UTF8, 0, buf, -1, &utf8[0], len, NULL, NULL);
return &utf8[0];
}
程序来自http://topic.csdn.net/u/20101008/12/895e5aaa-3db5-4c9f-8d06-ae7b04913132.html。
- C++中,将.txt文件的编码由UTF-8转换为ANSI
- C++中,将.txt文件的编码由UTF-8转换为ANSI
- .java文件的ANSI编码转换为UTF-8编码
- .java文件的ANSI编码转换为UTF-8编码
- ANSI、UNICODE、UTF-8 文件编码转换
- 【JAVA应用】批量将Java源文件的编码由GBK转换为UTF-8
- 将电脑新建文本文档txt的默认编码从ANSI改为utf-8
- 使用 native2ascii.exe 将java utf-8编码批量转换为 ANSI.
- C#中对上传的Txt文档进行编码的转换,并且不会乱码,其他编码转换为UTF-8
- C++文件编码由GBK转换UTF-8的解决方法
- C++文件编码由GBK转换UTF-8的解决方法
- 将一个ANSI编码格式纯文本文件以UTF-8的形式读到另一个文件中去
- //将一个ANSI编码格式纯文本文件以UTF-8的形式读到另一个文件中去
- 将字符串转换为UTF-8编码
- 将字符串的编码格式转换为utf-8
- 字符编码——在python2中如何将txt中的utf-8转换成中文
- ios中打开ANSI编码txt文件的办法
- UTF-8与ANSI 编码转换
- 写给学生:凭什么让好大学要你
- 恢复定居点和警方的三个角色的规划法计算的环境发生的话就放松放松的
- 浏览器变为编辑器
- 纪录片---BBC之睡眠十律笔记
- CareerCup chapter 2 Linked Lists
- C++中,将.txt文件的编码由UTF-8转换为ANSI
- DNS那点事之域名解析过程和原理
- easyui datagrid使用
- java atomic项目
- STM8 嵌入式特性编程之构建你的系统时间
- java swing实现的多线程实例代码教程-赛马demo
- poj-2586
- 温州设立政府“救助基金” 遇车祸先垫“救命钱”
- wdcp系统的安装