用boost验证整数、浮点数输入

来源:互联网 发布:收费在线视频网站源码 编辑:程序博客网 时间:2024/04/28 16:28

 

#include <boost/lexical_cast.hpp>

bool IsInteger(const std:string strInteger)
{
 try
 {
  int a = boost::lexical_cast<int>(strInteger);
 }
 catch (exception e)
 {
  //转换失败会执行到这里
  return false;
 } 

 return true;
}

bool IsDouble(const std::string strDouble)
{
 try
    {
  double a = boost::lexical_cast<double>(strDouble);
 }
 catch (exception e)
 {
  //转换失败会执行到这里
  return false;
 } 

 return true;