CString字符串中数字的提取。

CString字符串中数字的提取。
给出下列CString类型的字符串“192.168.1.1”,怎么提取其中的数字192 168 1 1并将其存到int类型的a,b,c,d中?
可以这么做,字符串化成单个字符输出,然后再原有基础上减去‘0’即可!
#include "stdio.h"
#include "afx.h"
void main()
{
CString str = "192.168.1.1";
int a,b,c,d;
int pos;
pos = str.Find('.');
CString temp;
temp = str.Left(pos);
a = atoi(temp);
str = str.Right(str.GetLength()-pos-1);
pos = str.Find('.');
temp = str.Left(pos);
b = atoi(temp);
str = str.Right(str.GetLength()-pos-1);
pos = str.Find('.');
temp = str.Left(pos);
c = atoi(temp);
str = str.Right(str.GetLength()-pos-1);
d = atoi(str);
printf("a=%d\nb=%d\nc=%d\nd=%d\n",a,b,c,d);
}
vc控者拆制台下还需要进行如猛贺下设置才能用MFC中的CString
工程中设置:工程项目属性-> 常枝嫌派规-> MFC的使用-> 在静态库中使用DLL
← 上一篇: 下一篇: →