zoukankan      html  css  js  c++  java
  • 1.把一个字符串内的正整数相加

     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 }
  • 相关阅读:
    购物网站被p.egou.com强制恶意劫持
    css下拉菜单
    StringToInt
    JframeMaxSize
    frameMaxSize
    inputChar
    英语要求
    sciAndSubject
    fileRename
    tensorflowOnWindows
  • 原文地址:https://www.cnblogs.com/ezhong/p/3973226.html
Copyright © 2011-2022 走看看