CString ss=_T(" 123 234 456");
char *p;
p=(LPSTR)(LPCTSTR)ss;
float X,Y,Z;
sscanf(pdd,"%f %f %f",&X,&Y,&Z);
只能得到x=1.000000
我想得到123,234,456
分别存到X,Y,Z中该如何
处理
char *p;
p=(LPSTR)(LPCTSTR)ss;
float X,Y,Z;
sscanf(pdd,"%f %f %f",&X,&Y,&Z);
只能得到x=1.000000
我想得到123,234,456
分别存到X,Y,Z中该如何
处理
CString _SubItem(CString str, LPCTSTR lpszSe, int stI, int endI)
{
if(stI == -1) return "";
int stPos, endPos;
//第一个逗号的位置
int prePos = 0;
while(stI > 0 && prePos != -1)
{
stI--;
prePos = str.Find(lpszSe, prePos);
if(prePos >= 0) prePos += strlen(lpszSe);
}
if(prePos == -1) stPos = str.GetLength();
else stPos = prePos; if(endI <= -1) endPos = str.GetLength();
else
{
prePos = 0;
while(endI > 0 && prePos != -1)
{
endI--;
prePos = str.Find(lpszSe, prePos);
if(prePos >= 0) prePos += strlen(lpszSe);
}
if(prePos == -1) endPos = str.GetLength();
else if(prePos == 0) endPos = 0;
else endPos = prePos - strlen(lpszSe);
} return str.Mid(stPos, endPos - stPos);
}
CString ss=_T(" 123 234 456");
CString strTmp = _SubItem(ss, " ", 0, 1);
float X,Y,Z;
x = atof(strTmp );
y = atof(_SubItem(ss, " ", 1, 2));
z = atof(_SubItem(ss, " ", 2, 3));这样就可以了,试一下