码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-09-15 19:11:49      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   ar   div   sp   log   on   

 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)把一个字符串内的正整数相加

标签:style   blog   color   os   ar   div   sp   log   on   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!