CString 与 std::string 相互转化
MFC中CString 与 std::string 相互转化
CString实际是CStringT, 也就是模板类,
在UNICODE环境下,实际是CStringW,
在多字符集环境下,实际是CStringA
std::string就是多字符集的.
UNICODE环境下
- CStringW-->std::string
CString实际是CStringW,要转换成多字符集,需进行转码。使用WideCharToMultiByte 转换成多字符集,然后再构造std::string
- std::string-->CStringW
因为CStringT模板类已经自动做了 char* 到 wchar_t* 的转码。
- 实例
//使用Unicode 字符集
CString strCS("HelloWorld");
USES_CONVERSION;
std::string strS(W2A(strCS)); //CString-->std::string
CString strCStemp;
strCStemp = strS.c_str();//std::string-->CString
注意:std::string-->CString时,不可以写在同一行:
CString strCStemp = strS.c_str();//ERROR
多字符集
CString 实际就是CStringA.
//CStringA-->std::string
CString strCS("HelloWorld");
std::string strS;
strS = strCS.GetBuffer(); //std::string-->CStringA
CString strCStemp = strS.c_str();//注意,可写在同一行
CString 与 std::string 相互转化的更多相关文章
- CString与std::string unicode下相互转化
1. CString to string CString str = L"test"; CString stra(str.GetBuffer(0)); str.ReleaseB ...
- CString转换成std::string
unicode的编码格式: CString strCS; std::string strSTD = CT2A(strCS.GetBuffer()); 其他的编码格式: CString strCS; ...
- CString std::string相互转换
CString->std::string 例子: CString strMfc=“test“; std::string strStl; strStl=strMfc.GetBuffer(0); s ...
- 实战c++中的string系列--std::string与MFC中CString的转换
搞过MFC的人都知道cstring,给我们提供了非常多便利的方法. CString 是一种非常实用的数据类型. 它们非常大程度上简化了MFC中的很多操作,使得MFC在做字符串操作的时候方便了非常多.无 ...
- std::string 和 CString问题
std::string stdTemp; CString strTemp; strTemp = stdTemp; ;//这一步直接赋值可不可以 因为CString可以接受const char*的 ...
- c++之常见数据类型(int,double,float,long double long long 与std::string之间)相互转换(含MFC的CString、含C++11新特性函数)
--- 已经通过初步测试---- ------------------ 下面的是传统常见数据类型的转换(非c++11)--------------- std::string 与其他常用类型相互转换, ...
- 17.Letter Combinations of a Phone Number (char* 和 string 相互转化)
leetcode 第17题 分析 char*和string相互转化 char*(或者char)转string 可以看看string的构造函数 default (1) string(); copy (2 ...
- C++: std::string 与 Unicode 结合
一旦知道 TCHAR 和_T 是如何工作的,那么这个问题很简单.基本思想是 TCHAR 要么是char,要么是 wchar_t,这取决于_UNICODE 的值: // abridged from tc ...
- C++: std::string 与 Unicode 如何结合?
关键字:std::string Unicode 转自:http://www.vckbase.com/document/viewdoc/?id=1293 一旦知道 TCHAR 和_T 是如何工作的,那么 ...
随机推荐
- WPF中图形表示语法详解(Path之Data属性语法)
原文 http://blog.csdn.net/johnsuna/article/details/1885597 老规矩,看图说话. 先看显示效果:(图1) XAML(代码A):<Page xm ...
- WMware VMX格式转换成OVF
1.关于VMX格式 vmx文件是vmware虚拟机系统的配置文件,注意:刚刚安装好VMware Workstation以后是找不到这个文件的,当你在VMware Workstation中建立了一个虚拟 ...
- hdu1728逃离迷宫 (利用最短路径思想+优先队列(BFS))
Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可以穿越,有 ...
- 如何同时激活两个不同版本的MyEclipse 【MyEclipse2013和MyEclipse2014同时激活】
激活一个MyEclipse的步骤,大家都会,在这里就不多说了,不会的可以看:http://jingyan.baidu.com/article/3ea51489cc14d452e71bba7a.html ...
- XMPP iOS开发(IM开发,转)
搭建完本地服务器之后,我们便可以着手客户端的工作,这里我们使用XMPPFramework这个开源库,安卓平台可以使用Smack(最好使用4.1以及之后的版本,支持流管理),为了简单起见这里只实现登陆. ...
- SDUT OJ 2783 小P寻宝记
#include<iostream> #include<memory.h> #define N 10020 using namespace std; int dp[N],pi[ ...
- Robotium双client測试框架
互联网的本质就是信息交换.移动互联网更是如此, 所以很多移动互联网的服务类应用中有着身份地位不同的两种用户(比如:交易中的买家和卖家, 教学中的老师和学生, 打车中的车主和乘客).近期的工作是给公司的 ...
- D. DZY Loves Modification
D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Android : Activity 和 TabActivity 共用一个OptionMenu
在虚拟机上我可以用menu键打开OptionMenu,但是到了真机上没有menu键了.OptionMenu没有办法打开,所以只能采用google推荐到ActionBar.用右上角到三个点代替实体到me ...
- SqlServer2008 数据库可疑
今天遇到数据库可疑,以前都是直接删了还原,这次没有最新的备份文件,一起看看脚本怎么解决 --最好一句句执行,方便看到错误 USE MASTER GO --开启数据库选项"允许更新" ...