天天看点

CString与int连接及相互转化

CString与int连接:

int localPort = RTP_TERMINAL_DEFAULT_LOCAL_PORT + nSelectRow;

CString url;

url.Format(_T("rtp://127.0.0.1:%d"),localPort);

//< 注意:不能直接使用CString与int类型 +

CString转为int:

CString str("1234");

int i= _ttoi(str);

在ANSI 和 UNICODE 都可以用的代码

int转为CString:

CString a;

int b = 0;

a.Format("%d", b);

另:

就是 CString::Format(LPCSTR, param.....)

没有直接将int转为CString这样的函数,一个是普通的数值变量,一个是类,没有可能转的。Format函数是把数值以文本模式字符串输出到CString里的