1 #include "string" 2 typedef std::basic_string<TCHAR> tstring; 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 }
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ezhong的博客签名-------------------------------------
以上内容来自ezhong的博客园,作者:ezhong
ezhong的博客园: http://www.cnblogs.com/ezhong
感谢您的阅读。感谢您的分享。