您的位置:首页 > 其它

1.把一个字符串内的正整数相加

2014-09-15 17:13 295 查看
#include "string"
typedef std::basic_string<TCHAR> tstring;
int _tmain(int argc, _TCHAR* argv[])
{

tstring str= _T("没2有60最脑40残只有100更脑残!5");
const tstring numSet = _T("0123456789");
tstring::size_type pos = str.find_first_of(numSet);
int iFinal(0);
while (str.npos != pos){
tstring::size_type pos2 = str.find_first_not_of(numSet, pos);
tstring strNum = str.substr(pos, pos2 - pos);
int iNum = _ttoi(strNum.c_str());
iFinal += iNum;
pos = str.find_first_of(numSet, pos2);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐