首页 > 其他 > 详细

脑残集(1)把一个字符串内的正整数相加

时间:2014-09-15 19:11:49      阅读:224      评论:0      收藏:0      [点我收藏+]
 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 }

 

脑残集(1)把一个字符串内的正整数相加

原文:http://www.cnblogs.com/ezhong/p/3973226.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!