当前位置:编程学习 > C/C++ >>

MFC类型转换那些事


MFC封装的类型跟C++对比,个人感觉很不习惯,有时候转个类型痛苦死了。特别是跟编码有关时,搞的特别郁闷,可能现在对MFC还不太熟。

有时候天真的想想MFC的类型底下为什么不带类型转换的方法,如果这样,用着多爽,一个方法就搞定,就不用百度谷歌那么多为什么了。

 

1.CString 转 int

[cpp] 
CString k; 
 
int  i=_ttoi(k); 
CString k;

int  i=_ttoi(k);

 

 

2.int,char,string 转 CString

[cpp] 
CString ss; 
 
int i; 
 
string str; 
 
char  *ch; 
 
ss.Format("%d,%s,%s",i,str.c_str(), ch); 
CString ss;

int i;

string str;

char  *ch;

ss.Format("%d,%s,%s",i,str.c_str(), ch);

 

3. CString转string

[cpp] www.zzzyk.com
CString ss;  
 
string strNowGroupInfo = CStringA(ss);    
CString ss;

string strNowGroupInfo = CStringA(ss);  
 

 

 

作者:wyz365889
补充:软件开发 , C++ ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,