#include <typeinfo> template <typename T> bool a2x( T& _f , char* p) { if( !p ) return false ; char* q = p ; while( q != ‘\0‘) { if( *q == ‘-‘ && *(q+1) >= ‘0‘ && *(q+1)<= ‘9‘ ) { break ; } if( *q >= ‘0‘ && *q <= ‘9‘ ) break ; q++ ; } if( q ==‘\0‘) return false ; if(typeid(float).name() == typeid(_f).name() ) sscanf(q,"%f",&_f ); else if(typeid(int).name() == typeid(_f).name() ) sscanf(q,"%d",&_f ); else if(typeid(long).name() == typeid(_f).name() ) sscanf(q,"%ld",&_f ); else if(typeid(double).name() == typeid(_f).name() ) sscanf(q,"%lf",&_f ); else return false ; return true ; }
时间: 2024-10-07 05:06:48