扁平疣可以报医保吗:CString s = "12,78,89,78,89,45";转化为int ??

来源:百度文库 编辑:神马品牌网 时间:2024/04/29 12:45:27
CString s = "12,78,89,78,89,45";
如何转换成一个数组
int a[] = {12,78,89,78,89,45}; ???
或者将CString中的数字逐个提取出来为int型??
在开发VC++程序中要用到!!
望指教!
现在我已经知道如下方法:
int a[6];
sscanf((LPTSTR)LPCTSTR(str), "%d.%d.%d.%d.%d.%d.", &a[0],&a[1],&a[2],&a[3],&a[4],&a[5]));
//结果
a[0]=12,a[1]=78,^^^^^^^a[5]=45;
问题是:上述方法 较死板了,如果数字个数在动态的变动就不灵活了!
继续求问!

楼上的,方法太死板了。

还是用STL库的getline来处理这个串比较好,显然数字是用逗号,分开的,而不是固定的两位,万一还有空格呢?
你的方法不是失效了么?

得到了每个数字的串之后,用atoi函数来做就可以了。不然用sscanf

CString m_oStrData;
BYTE tmp;
for(i = 0; i < 16; i++)
{
tmp = m_oStrData.GetAt(i*2 +1);
if(tmp <= 0x39)
{
oHexData[i] = (m_oStrData.GetAt(i*2+1) - 0x30);
}
else
{
oHexData[i] = (m_oStrData.GetAt(i*2+1) - 0x37);
}

oHexData[i] <<= 4;

tmp = m_oStrData.GetAt(i*2);
if(tmp <= 0x39)
{
oHexData[i] += (m_oStrData.GetAt(i*2) - 0x30);
}
else
{
oHexData[i] += (m_oStrData.GetAt(i*2) - 0x37);
}
}

同意楼上的说法,虽然不懂C++语言,但是说到用库函数中的函数还是很明知的,其他的语言一样的 还的很灵活的