CString字串中數字的提取
阿新 • • 發佈:2018-11-14
假設CString型別的字串“192.168.1.1”
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); }
輸出:
a=192
b=168
c=1
d=1
vc控制檯下還需要進行如下設定才能用MFC中的CString
工程中設定:工程專案屬性-> 常規-> MFC的使用-> 在靜態庫中使用DLL