• <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 閱讀(379) 評論(0)  編輯 收藏 引用

            導航

            統計

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            99蜜桃臀久久久欧美精品网站| 久久久婷婷五月亚洲97号色| 伊人久久大香线蕉精品| 一级做a爰片久久毛片人呢| 亚洲精品高清国产一久久| 亚洲?V乱码久久精品蜜桃| 久久无码高潮喷水| 国产精品久久久久天天影视| 色成年激情久久综合| 久久亚洲sm情趣捆绑调教| 久久久国产精品福利免费| 亚洲午夜久久久| segui久久国产精品| 亚洲国产精品无码久久一线| 久久综合丁香激情久久| 久久精品国产久精国产一老狼| 久久精品国产秦先生| 天天躁日日躁狠狠久久| 久久久久亚洲AV成人网人人软件| 亚洲欧洲日产国码无码久久99| 久久国产成人| 伊人久久综合热线大杳蕉下载| 囯产精品久久久久久久久蜜桃| 久久本道综合久久伊人| 国产精品久久久久久久久久免费| 国产精品无码久久综合| 色诱久久久久综合网ywww| 成人综合久久精品色婷婷| 久久亚洲欧洲国产综合| 精品国产91久久久久久久a| 97久久国产亚洲精品超碰热| 色欲综合久久躁天天躁蜜桃| 无码任你躁久久久久久老妇App| 欧美与黑人午夜性猛交久久久 | 99久久国产主播综合精品| 久久人人爽人人爽人人片av高请| 综合久久一区二区三区 | 久久久久久国产精品美女| 国产日韩久久久精品影院首页| 久久亚洲国产午夜精品理论片| 国产综合久久久久久鬼色|