读书人

利用STL判断string是不是为整数

发布时间: 2012-10-06 17:34:01 作者: rapoo

利用STL判断string是否为整数

有这么一个文件,内容如下:

?

#include <string>#include <iostream>#include<fstream>#include<algorithm>#include<vector>using namespace std;int ismun(string strinfo){string strset="1234567890";int first = strinfo.find_first_of(strset);if(first == string::npos) {return -1;}  return 0;}int main(){ifstream in("proc.txt");string strtemp;vector<string> myvector;while(getline(in,strtemp,'\n')){if(ismun(strtemp) == 0){myvector.push_back(strtemp);}}vector<string>::iterator it;for(it = myvector.begin();it != myvector.end();it ++){cout<<*it<<endl;}return 0;}

?

?函数介绍:

find_first_of()函数介绍:

?

?

find_first_of?

语法: size_type find_first_of( const basic_string &str, size_type index = 0 );?

size_type find_first_of( const char *str, size_type index = 0 );?

size_type find_first_of( const char *str, size_type index, size_type num );?

size_type find_first_of( char ch, size_type index = 0 );?

?

?

find_first_of()函数:?

?

查找在字符串中第一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,如果没找到就返回string::npos?

查找在字符串中第一个与str中的某个字符匹配的字符,返回它的位置。搜索从index开始,最多搜索num个字符。如果没找到就返回string::npos,?

查找在字符串中第一个与ch匹配的字符,返回它的位置。搜索从index开始。

?

?

读书人网 >编程

热点推荐