头文件: #ifndef __VALIDFILTER__H#define __VALIDFILTER__H#define VALIDFILTER_FLOATNUM "([0-9]+).([0-9]+)|([0-9]+)"#define VALIDFILTER_FLOAT "([0-9]+).([0-9]+)"#define VALIDFILTER_NUM "[0-9]+"#define VALIDFILTER_ALPHABET "[a-z]+"#define VALIDFILTER_ ""#include <iostream>#include <boost/regex.hpp>using namespace boost;using namespace std;class validfilter{public: validfilter(void); ~validfilter(void); bool IsFloatAndNum( std::string value); bool IsFloat( std::string value); bool IsNum( std::string value); bool IsAlphabet( std::string value);private: bool validmatch( std::string& value,std::string regex_expression);};#endif .cpp #include "validfilter.h"using namespace boost;using namespace std;validfilter::validfilter(void){}validfilter::~validfilter(void){}bool validfilter::IsFloatAndNum( std::string value){ return validmatch( value,VALIDFILTER_FLOATNUM);}bool validfilter::IsFloat( std::string value){ return validmatch( value,VALIDFILTER_FLOAT); }bool validfilter::IsNum( std::string value){ return validmatch( value,VALIDFILTER_NUM); }bool validfilter::IsAlphabet( std::string value){ return validmatch( value,VALIDFILTER_ALPHABET);}bool validfilter::validmatch( std::string& value,std::string regex_expression){ if( value.empty() || regex_expression.empty() ) return false; boost::regex expression(regex_expression); if( regex_match( value,expression)) //字符串匹配 { return true; } else { return false; } } demo测试程序 #include <iostream>#include <stdio.h>#include "validfilter.h"using namespace std;int _tmain(int argc, _TCHAR* argv[]){ validfilter filter; bool state; std::string str; while(1) { cout<<"input:"<<endl; cin>> str; if( filter.IsFloatAndNum( str ) ) { cout<<"数字浮点"<<endl; continue; } if( filter.IsAlphabet( str ) ) { cout<<"字母"<<endl; continue; } if( filter.IsFloat( str )) { cout<<"浮点"<<endl; continue; } if( filter.IsNum(str) ) { cout<<"数字"<<endl; continue; } if( str == "quit") { return 0; } } return 0;} 文件:validfilter.rar大小:0KB下载:下载 阅读(370) | 评论(0) | 转发(0) | 0 上一篇:适用boost regex检测 输入字符为小数 下一篇:VC2005中list control控件如何获得选中的行 相关热门文章 test123编写安全代码——小心有符号数...使用openssl api进行加密解密...一段自己打印自己的c程序...sql relay的c++接口 GCC编译命令推荐系统常用算法C++Primer笔记 第八章 标准IO...c语言中的#号和##号的作用...gstreamer插件开发-------sink... 给主人留下些什么吧!~~ 评论热议