Advertisement

分析和总结 MFC 中常见的数据类型转换方式

阅读量:

一、string与CString之间的相互转换

1、CString向string的转换:

复制代码
 CString msg = _T("abc");

    
 std::string strmsg(W2A(msg));
    
    
    
    

2、string2CString:

复制代码
 std::string msg = "abc";

    
 CString strmsg = CString(msg.c_str());
    
    
    
    

二、字符串(CString)与整型数值之间的相互转换

1、字符串向整型数值的转换

复制代码
 std::string strValue = "2018";

    
 int nValue = atoi(strValue.c_str());
    
    
    
    

2、整数转字符串

复制代码
 int nValue = 2018;

    
 std::string strValue = to_string(nValue);
    
    
    
    

3、CString转整型

复制代码
 CString year = _T("2018");

    
 int nYear = _ttoi(year);
    

全部评论 (0)

还没有任何评论哟~