1 #include "string" 2 typedef std::basic_stringtstring; 3 int _tmain(int argc, _TCHAR* argv[]) 4 { 5 6 tstring str= _T("没2有60最脑40残只有100更脑残!5"); 7 const tstring numSet = _T("0123456789"); 8 tstring::size_type pos = str.find_first_of(numSet); 9 int iFinal(0);10 while (str.npos != pos){11 tstring::size_type pos2 = str.find_first_not_of(numSet, pos);12 tstring strNum = str.substr(pos, pos2 - pos);13 int iNum = _ttoi(strNum.c_str());14 iFinal += iNum;15 pos = str.find_first_of(numSet, pos2);16 }17 18 return 0;19 }