boost::lexical_cast简单实现

来源:互联网 发布:linux netstat 状态 编辑:程序博客网 时间:2024/05/16 12:56
#include <sstream>template< typename Output, typename Input >Output custom_cast( const Input &In ){std::stringstream Converter;//关键核心使用字符流Converter << In;//写入数据Output Out;Converter >> Out;//输出数据return Out;}int main(){    float a = custom_cast< float >( "123" );    double b = custom_cast< int >( 123 );    std::string c = custom_cast< std::string >( 123.0 );    int d = custom_cast< int >( "123" );    return 0; }

0 0
原创粉丝点击