• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Robin Chow's C++ Blog

             

            [導入]Convert from string to int

            The methods: 1) From the C standard library, using atoi:
            #include 
            #include 
            std::string text = "152"; 
            int number = std::atoi( text.c_str() ); 
            if (errno == ERANGE) //that may be std::errno 
            { 
            //the number was too big/small to store completely, number is either LONG_MAX or LONG_MIN 
            } 
            else if (errno == ????) 
            //maybe EINVAL? not sure, man page dosn't seem to say... 
            //other possibilities are E2BIG and EDOM (or ERANGE maybe again)... 
            //but I'd vote for EINVAL 
            { 
            //unable to convert to a number 
            }
            2) From the C++ standard library, using strstream:
            #include 
            #include 
            std::string text = "152"; 
            int number; 
            std::istringstream ss( text ); 
            ss >> number; 
            if (! ss.good()) 
            { 
            //something happened 
            }
            3) From the Boost library, using lexical_cast:
            #include 
            #include  
            
            try 
            { 
            std::string text = "152"; 
            int number = boost::lexical_castint >( text ); 
            } 
            catch( const boost::bad_lexical_cast & ) 
            { 
            //unable to convert 
            }

            文章來源:http://my.donews.com/robinchow/2007/04/17/post-070417-111701-329/

            posted on 2007-10-23 20:45 Robin Chow 閱讀(378) 評論(0)  編輯 收藏 引用

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久国产欧美日韩精品| 久久国产免费观看精品3| 久久婷婷五月综合97色直播| 蜜臀av性久久久久蜜臀aⅴ | 久久天天躁狠狠躁夜夜av浪潮| 人妻无码αv中文字幕久久琪琪布| 一本色道久久88加勒比—综合| 综合久久给合久久狠狠狠97色| 观看 国产综合久久久久鬼色 欧美 亚洲 一区二区 | 久久精品国产69国产精品亚洲| 亚洲天堂久久久| 久久精品国产久精国产思思| 青青草原1769久久免费播放| 久久青青草原亚洲av无码app| 99久久精品国产综合一区| 国产精品久久久久蜜芽| 久久久久久久综合日本亚洲 | 91久久精品国产成人久久| 一本色道久久88综合日韩精品 | 久久免费的精品国产V∧| 99久久精品免费看国产一区二区三区 | 久久久久久国产a免费观看黄色大片 | 精品无码久久久久国产动漫3d | 欧洲精品久久久av无码电影| 国产精品永久久久久久久久久| 色噜噜狠狠先锋影音久久| 国内精品伊人久久久久妇| 嫩草影院久久国产精品| 亚洲AV无码久久精品色欲| 成人久久免费网站| 亚洲精品无码成人片久久| 91亚洲国产成人久久精品| 久久这里只有精品18| 性高湖久久久久久久久AAAAA| 久久99精品国产麻豆婷婷| 色欲av伊人久久大香线蕉影院| 久久精品一区二区国产| 久久综合给合久久狠狠狠97色69 | 精品国产乱码久久久久久1区2区| 亚洲精品成人久久久| 精品久久777|