1、先添加头问题件:
#include<string>
using namespace std; //注意,一定要加分号符;
2、提取数字字符串
CString cstr = _T("abc123");
int iLen = cstr.GetLength();
CString cstrTemp;
for(int i = 0; i< iLen; i ++)
{
if(cstr.GetAt(i) >= '0' && cstr.GetAt(i) <= '9')
cstrTemp+= cstrTemp.GetAt(i);
}
3、数字字符串转为int
char buf[100] = {};//是将cstr中的内容拷贝到buf
//然后先将CString转为string,再由c_str()转为const char*
string str = CStringA(cstr);
strncpy_s(buf, _countof(buf), str.c_str(), cstr.GetLength());
int i = atoi(buf); //字符转为数字