工具类CTools实现字符编码转换和获取当前路径
class CTools
{
public:
CTools(void);
public:
~CTools(void);
public:
static std::string UNICODE_to_UTF8(const CString& unicodeString);
static CString UTF8_to_UNICODE(const std::string& utf8_string);
static std::string ws2s(std::wstring& inputws);
static std::wstring s2ws(const std::string& s); static std::string UNICODE_to_ANSI(const CString& unicodeString);
static CString ANSI_to_UNICODE(const std::string& utf8_string); static std::string GetFullPath(void);
}; CTools::CTools(void)
{
} CTools::~CTools(void)
{
} std::string CTools::UNICODE_to_UTF8(const CString& unicodeString)
{
int stringLength = ::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, (int)wcslen(unicodeString), NULL, , NULL, NULL); char* buffer = new char[stringLength + ];
::WideCharToMultiByte(CP_UTF8, NULL, unicodeString, (int)wcslen(unicodeString), buffer, stringLength, NULL, NULL);
buffer[stringLength] = '\0'; std::string str = buffer; delete[] buffer; return str;
} CString CTools::UTF8_to_UNICODE(const std::string& utf8_string)
{
int length = (int)utf8_string.size(); int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, utf8_string.c_str(), length, NULL, );
wchar_t* wszString = new wchar_t[wcsLen + ];
::MultiByteToWideChar(CP_UTF8, NULL, utf8_string.c_str(), length, wszString, wcsLen);
wszString[wcsLen] = '\0';
CString unicodeText(wszString);
delete[] wszString; return unicodeText;
} std::string CTools::UNICODE_to_ANSI(const CString& unicodeString)
{
int stringLength = ::WideCharToMultiByte(CP_ACP, NULL, unicodeString, (int)wcslen(unicodeString), NULL, , NULL, NULL); char* buffer = new char[stringLength + ];
::WideCharToMultiByte(CP_ACP, NULL, unicodeString, (int)wcslen(unicodeString), buffer, stringLength, NULL, NULL);
buffer[stringLength] = '\0'; std::string str = buffer; delete[] buffer; return str;
} CString CTools::ANSI_to_UNICODE(const std::string& utf8_string)
{
int length = (int)utf8_string.size(); int wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, utf8_string.c_str(), length, NULL, );
wchar_t* wszString = new wchar_t[wcsLen + ];
::MultiByteToWideChar(CP_ACP, NULL, utf8_string.c_str(), length, wszString, wcsLen);
wszString[wcsLen] = '\0';
CString unicodeText(wszString);
delete[] wszString; return unicodeText;
} std::string CTools::ws2s(std::wstring& inputws)
{
return UNICODE_to_UTF8(inputws.c_str());
} std::wstring CTools::s2ws(const std::string& s)
{
CString cstr = UTF8_to_UNICODE(s);
return cstr.GetBuffer(cstr.GetLength());
} std::string CTools::GetFullPath(void)
{
HMODULE h = GetModuleHandle(L"Test.exe");
wchar_t exeFullPath[MAX_PATH]; // MAX_PATH在API中有定义,为128
int len=GetModuleFileName(h,
exeFullPath, //应用程序的全路径存放地址
MAX_PATH);
std::wstring wstrpath = exeFullPath;
std::string strpath = CTools::ws2s(wstrpath);
size_t nPos;
nPos=strpath.rfind('\\');
return strpath.substr(,nPos);
}
工具类CTools实现字符编码转换和获取当前路径的更多相关文章
- Char Tools,方便的字符编码转换小工具
工作关系,常有字符编码转换方面的需要,写了这个小工具 Char Tools是一款方便的字符编码转换小工具,基于.Net Framework 2.0 Winform开发 主要功能 URL编码:URLEn ...
- 编码问题 php字符编码转换类
各种平台和软件打开显示的编码问题,需要使用不同的编码,根据我们不同的需求. php 字符编码转换类,支持ANSI.Unicode.Unicode big endian.UTF-8.UTF-8+Bom ...
- iconv字符编码转换
转自 http://blog.csdn.net/langresser_king/article/details/7459367 iconv(http://www.gnu.org/software/li ...
- php字符编码转换之gb2312转为utf8(转)
在php中字符编码转换我们一般会用到iconv与mb_convert_encoding进行操作,但是mb_convert_encoding在转换性能上比iconv要差很多哦.string iconv ...
- php 字符编码转换函数 iconv mb_convert_encoding比较
在使用PHP处理字符串时,我们经常会碰到字符编码转换的问题,你碰到过iconv转换失败吗? 发现问题时,网上搜了搜,才发现iconv原来有bug ,碰到一些生僻字就会无法转换,当然了配置第二个参数时, ...
- Python—字符编码转换、函数基本操作
字符编码转换 函数 #声明文件编码,格式如下: #-*- coding:utf-8 -*- 注意此处只是声明了文件编码格式,python的默认编码还是unicode 字符编码转换: import sy ...
- day4学python 字符编码转换+元组概念
字符编码转换+元组概念 字符编码转换 #coding:gbk //此处必声明 文件编码(看右下角编码格式) #用来得到python默认编码 import sys print(sys.getdefaul ...
- erlang中字符编码转换(转)
转自:http://www.thinksaas.cn/group/topic/244329/ 功能说明: erlang中对各种语言的编码支持不足,此代码是使用erlang驱动了著名的iconv编码库来 ...
- Qt代码区字符编码转换
在做通讯练习的时候,发现发送给小助手字符乱码,图片如下 本人Qt Creator是UTF-8,需要改成gbk,代码如下 #include<QTextCodec> // 提供字符编码转换 Q ...
随机推荐
- HDU1181【有向图的传递闭包】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1181 题意很简单. 有用并查集做的.我这里用传递闭包做. 有向图的传递闭包采用Floyd思想,可以判断 ...
- Intersecting Lines(数学)
Intersecting Lines Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12844 Accepted: 57 ...
- 道路软件质量:SourceMonitor
有些事情必须这样做,不是幸福,但是,缓解疼痛,因为不.更痛苦--这是无奈. 夏中义 <文心独白> 1 简介 博客没有更新了一段时间,了阿里上市的成功之处:选择和坚持.事实上人生并没有绝对的 ...
- HTTP消息头详解
HTTP是一个属于应用层面的面向对象的协议,由于其便捷.快速的方式.适用于分布式超媒体信息系统.于1990年提出 HTTP 协议主要特点概括如下 1.支持客户/服务器模式. 2.简单快速 请求方法常用 ...
- 解决Jedis数据读取乱码问题
现象 同一套代码,同一个数据源,不同的操作系统,在OSX上数据提取编码正常,而Ubuntu上拉取数据乱码,数据拉取代码如下. @Override public List<String> m ...
- 如何在macox下面配置集成ios和android游戏教程
教程截图: 1.准备工作,配置开发环境: 开发环境:mac ox 10.7.3 + xcode4.2 + ndk r7 + eclipse helios 部署环境:中兴v880 root过了 ...
- ThinkPHP第六天(正则表达式)
1.正则表达式:原子 ①a-z,A-Z,0-9,_ ②用(abc)圆括号括起来的单元符号,表示括号里面的作为一个完整的组合,必须完成匹配,不被拆分来 ③用方括号括起来[abc][^abc]称之为原子表 ...
- poj 1905 Expanding Rods 二分
/** 题解晚上写 **/ #include <iostream> #include <math.h> #include <algorithm> #include ...
- QT通过IP地址定位地址(用get方法取数据)
通过IP地址定位地址,是要通过查询数据库,如果自己做一个这样的数据库工作量就比较大,所以在网上找了一个查询IP地址的网址,通过调用这个网址查询来实现,但是这个有一定的弊端,如果没有网络或者这个网址不可 ...
- Java学习之二分查找算法
好久没写算法了.只记得递归方法..结果测试下爆栈了. 思路就是取范围的中间点,判断是不是要找的值,是就输出,不是就与范围的两个临界值比较大小,不断更新临界值直到找到为止,给定的集合一定是有序的. 自己 ...