• <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)

            隨筆分類

            隨筆檔案

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            久久青青草视频| 亚洲综合熟女久久久30p| 91精品国产高清久久久久久io| 亚洲精品无码久久久久sm| 久久久久亚洲AV无码专区体验| 伊人久久综合无码成人网| 蜜桃麻豆www久久| 亚洲精品第一综合99久久| 久久国产免费观看精品3| 久久国产精品一区| 久久精品国产亚洲av影院| 久久久青草青青国产亚洲免观| 久久婷婷五月综合成人D啪 | 狠狠色综合久久久久尤物| 伊人久久成人成综合网222| 久久久无码一区二区三区| 久久精品国产国产精品四凭| 亚洲狠狠婷婷综合久久久久 | 久久久九九有精品国产| 伊人色综合久久天天人守人婷| 免费国产99久久久香蕉| 一本一道久久综合狠狠老| 久久精品18| 久久国产成人亚洲精品影院| 国产精品久久网| 久久国产精品成人片免费| 亚洲AV无码久久精品成人 | 久久久精品波多野结衣| 久久香蕉国产线看观看精品yw| 久久亚洲国产成人影院网站| 亚洲国产精品一区二区久久| 久久精品无码一区二区无码| 亚洲狠狠婷婷综合久久久久 | 久久精品国产69国产精品亚洲| 精品久久亚洲中文无码| 久久综合亚洲色HEZYO社区| 久久亚洲高清综合| 一本久久免费视频| 亚洲中文字幕无码久久2017| 一本色道久久99一综合| 久久人人爽人人爽人人片AV麻烦|