find_first_of查找string中的所有数字

/******************************************************************************
 * 用str.find_first_of(cstr, pos)查找str中的所有数字,
 * 算法:没查找到一个pos,从该pos的下一元素重新查找。
 ********************************************************************************/

#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str = "he2L3L5oWo6rLD";
	string::size_type pos = 0;
	while ((pos = str.find_first_of("0123456789", pos)) != string::npos) {
		cout << str[pos];
		pos++;
	}

	return 0;
}
posted @ 2012-12-18 22:36  helloweworld  阅读(346)  评论(0编辑  收藏  举报