MFC中CString类字符串与长整型、浮点型、字符数组char数据之间的相互转换
一、長(zhǎng)整型數(shù)據(jù)與CString類字符串相互轉(zhuǎn)換
1.將長(zhǎng)整型數(shù)據(jù)轉(zhuǎn)換為CString字符串類
CString str;
long ld;
str.Format(_T("%ld"),ld);
2.將CString字符串類轉(zhuǎn)換為長(zhǎng)整型數(shù)據(jù)
CString str;
long ld;
ld=_wtol(str);
_wtol()在<stdlib.h> and <wchar.h>中
二、浮點(diǎn)型數(shù)據(jù)與CString類字符串相互轉(zhuǎn)換
1.將浮點(diǎn)型數(shù)據(jù)轉(zhuǎn)換為CString類字符串
CString ?str;
double ss;
str.Format(_T("%f"),ss);
2.將CString類字符串轉(zhuǎn)換為浮點(diǎn)型數(shù)據(jù)
CString ?str;
double ss;
ss=_wtof(str);
_wtof()在<stdlib.h> or<wchar.h>中
三、將整型數(shù)據(jù)轉(zhuǎn)換為CString字符串類
CString str;
int n=1;
str.Format(_T("%c"),n+65);//這樣str=”B”;
四、字符數(shù)組與CString字符串類相互轉(zhuǎn)換
1. 將字符數(shù)組轉(zhuǎn)換為CString字符串類
CString str;
char buffer[100];
str.Format(_T("%s"),buffer);
或者str=buffer;
2. 將CString字符串類轉(zhuǎn)換為字符數(shù)組
CString str;
char buffer[100];
int i;
for(i=0;i<str.GetLength();i++)
{
????? buffer[i]=(char)(str.GetAt(i));
}
buffer[i]='\0';
?
?
更加詳細(xì)內(nèi)容參考VS2010 MSDN
?
總結(jié)
以上是生活随笔為你收集整理的MFC中CString类字符串与长整型、浮点型、字符数组char数据之间的相互转换的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Python 3深度置信网络(DBN)在
- 下一篇: 配置设备作为DHCP 服务器(基于接口地