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; }
相关文章推荐
- (原創) 写一个字符串相加产生整数的function (C/C++)
- 导师作业:2、编写一个函数,将一个整数值转换为16进制表示的字符串。
- 1.编写一个程序,这个程序把一个整数数组中的每个元素用逗号连接成一个字符串,例如,根据内容为[1][2][3]的数组形成内容
- 整数转变成字符串遇到的一个问题
- 将一个字符串中的各个位按递增排序的最大整数打印出来
- [导入]一个将整数转换成字符串的函数itoa
- 判断一个字符串不是整数
- 在sql server数据库里面要把一个字符串转换为整数
- 判断一个字符串是否为整数
- C++读取以空格作为数据区分标记,以回车为行标记的txt文件到一个整数数组(字符串妙用)
- 求一个字符串中所有连续的整数和
- 计算机笔试题:写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整型的函数)
- 关于存在一个正整数n,使得大于n的整数都能由6、9、20相加组合而成的证明
- 在sql server数据库里面要把一个字符串转换为整数
- 求一个正整数是由哪几个连数(连续的正整数)相加
- 用递归法将一个整数n转换成字符串。
- JavaScript 判断一个字符串是不是数字(整数或浮点数)
- 将一个整数n转换成换成一个字符串。如将1234转换为"1234"。
- C#判断一个字符串是否为整数
- C# 一个整数个位十位百位单个相加